File: passwordless.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 (76 lines) | stat: -rw-r--r-- 2,397 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import annotations

from typing import Any

from .base import AuthenticationBase


class Passwordless(AuthenticationBase):

    """Passwordless connections endpoints.

    Args:
        domain (str): Your auth0 domain (e.g: my-domain.us.auth0.com)
    """

    def email(
        self, email: str, send: str = "link", auth_params: dict[str, str] | None = None
    ) -> Any:
        """Start flow sending an email.

        Given the user email address, it will send an email with:

          - A link (default, send:"link"). You can then authenticate with
            this user opening the link and he will be automatically logged in
            to the application. Optionally, you can append/override
            parameters to the link (like scope, redirect_uri, protocol,
            response_type, etc.) using auth_params dict.

          - A verification code (send:"code"). You can then authenticate with
            this user using email as username and code as password.

        Complete the authentication using the get_token.passwordless_login method.

        Args:
            email (str): Email address.

            send (str, optional): Can be: 'link' or 'code'. Defaults to 'link'.

            auth_params (dict, optional): Parameters to append or override.
        """

        data: dict[str, Any] = {
            "client_id": self.client_id,
            "connection": "email",
            "email": email,
            "send": send,
        }
        if auth_params:
            data.update({"authParams": auth_params})

        return self.authenticated_post(
            f"{self.protocol}://{self.domain}/passwordless/start", data=data
        )

    def sms(self, phone_number: str) -> Any:
        """Start flow sending an SMS message.

        Given the user phone number, it will send an SMS with
        a verification code. You can then authenticate with
        this user using phone number as username and code as password.

        Complete the authentication using the get_token.passwordless_login method.

        Args:
            phone_number (str): Phone number.
        """

        data = {
            "client_id": self.client_id,
            "connection": "sms",
            "phone_number": phone_number,
        }

        return self.authenticated_post(
            f"{self.protocol}://{self.domain}/passwordless/start", data=data
        )