| 1 | from __future__ import annotations |
| 2 | |
| 3 | from typing import Any |
| 4 | |
| 5 | from .base import AuthenticationBase |
| 6 | |
| 7 | |
| 8 | class Passwordless(AuthenticationBase): |
| 9 | |
| 10 | """Passwordless connections endpoints. |
| 11 | |
| 12 | Args: |
| 13 | domain (str): Your auth0 domain (e.g: my-domain.us.auth0.com) |
| 14 | """ |
| 15 | |
| 16 | def email( |
| 17 | self, email: str, send: str = "link", auth_params: dict[str, str] | None = None |
| 18 | ) -> Any: |
| 19 | """Start flow sending an email. |
| 20 | |
| 21 | Given the user email address, it will send an email with: |
| 22 | |
| 23 | - A link (default, send:"link"). You can then authenticate with |
| 24 | this user opening the link and he will be automatically logged in |
| 25 | to the application. Optionally, you can append/override |
| 26 | parameters to the link (like scope, redirect_uri, protocol, |
| 27 | response_type, etc.) using auth_params dict. |
| 28 | |
| 29 | - A verification code (send:"code"). You can then authenticate with |
| 30 | this user using email as username and code as password. |
| 31 | |
| 32 | Complete the authentication using the get_token.passwordless_login method. |
| 33 | |
| 34 | Args: |
| 35 | email (str): Email address. |
| 36 | |
| 37 | send (str, optional): Can be: 'link' or 'code'. Defaults to 'link'. |
| 38 | |
| 39 | auth_params (dict, optional): Parameters to append or override. |
| 40 | """ |
| 41 | |
| 42 | data: dict[str, Any] = { |
| 43 | "client_id": self.client_id, |
| 44 | "connection": "email", |
| 45 | "email": email, |
| 46 | "send": send, |
| 47 | } |
| 48 | if auth_params: |
| 49 | data.update({"authParams": auth_params}) |
| 50 | |
| 51 | return self.authenticated_post( |
| 52 | f"{self.protocol}://{self.domain}/passwordless/start", data=data |
| 53 | ) |
| 54 | |
| 55 | def sms(self, phone_number: str) -> Any: |
| 56 | """Start flow sending an SMS message. |
| 57 | |
| 58 | Given the user phone number, it will send an SMS with |
| 59 | a verification code. You can then authenticate with |
| 60 | this user using phone number as username and code as password. |
| 61 | |
| 62 | Complete the authentication using the get_token.passwordless_login method. |
| 63 | |
| 64 | Args: |
| 65 | phone_number (str): Phone number. |
| 66 | """ |
| 67 | |
| 68 | data = { |
| 69 | "client_id": self.client_id, |
| 70 | "connection": "sms", |
| 71 | "phone_number": phone_number, |
| 72 | } |
| 73 | |
| 74 | return self.authenticated_post( |
| 75 | f"{self.protocol}://{self.domain}/passwordless/start", data=data |
| 76 | ) |