File: delegated.py

package info (click to toggle)
auth0-python 4.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,280 kB
  • sloc: python: 8,933; makefile: 15; sh: 2
file content (44 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import annotations

from typing import Any

from .base import AuthenticationBase


class Delegated(AuthenticationBase):
    """Delegated authentication endpoints.

    Args:
        domain (str): Your auth0 domain (e.g: username.auth0.com)
    """

    def get_token(
        self,
        target: str,
        api_type: str,
        grant_type: str,
        id_token: str | None = None,
        refresh_token: str | None = None,
        scope: str = "openid",
    ) -> Any:
        """Obtain a delegation token."""

        if id_token and refresh_token:
            raise ValueError("Only one of id_token or refresh_token can be None")

        data = {
            "client_id": self.client_id,
            "grant_type": grant_type,
            "target": target,
            "scope": scope,
            "api_type": api_type,
        }

        if id_token:
            data.update({"id_token": id_token})
        elif refresh_token:
            data.update({"refresh_token": refresh_token})
        else:
            raise ValueError("Either id_token or refresh_token must have a value")

        return self.post(f"{self.protocol}://{self.domain}/delegation", data=data)