File: database.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 (108 lines) | stat: -rw-r--r-- 3,332 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from __future__ import annotations

from typing import Any

from .base import AuthenticationBase


class Database(AuthenticationBase):
    """Database & Active Directory / LDAP Authentication.

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

    def signup(
        self,
        email: str,
        password: str,
        connection: str,
        username: str | None = None,
        user_metadata: dict[str, Any] | None = None,
        given_name: str | None = None,
        family_name: str | None = None,
        name: str | None = None,
        nickname: str | None = None,
        picture: str | None = None,
    ) -> dict[str, Any]:
        """Signup using email and password.

        Args:
           email (str): The user's email address.

           password (str): The user's desired password.

           connection (str): The name of the database connection where this user should be created.

           username (str, optional): The user's username, if required by the database connection.

           user_metadata (dict, optional): Additional key-value information to store for the user.
                    Some limitations apply, see: https://auth0.com/docs/metadata#metadata-restrictions

           given_name (str, optional): The user's given name(s).

           family_name (str, optional): The user's family name(s).

           name (str, optional): The user's full name.

           nickname (str, optional): The user's nickname.

           picture (str, optional): A URI pointing to the user's picture.


        See: https://auth0.com/docs/api/authentication#signup
        """
        body: dict[str, Any] = {
            "client_id": self.client_id,
            "email": email,
            "password": password,
            "connection": connection,
        }
        if username:
            body.update({"username": username})
        if user_metadata:
            body.update({"user_metadata": user_metadata})
        if given_name:
            body.update({"given_name": given_name})
        if family_name:
            body.update({"family_name": family_name})
        if name:
            body.update({"name": name})
        if nickname:
            body.update({"nickname": nickname})
        if picture:
            body.update({"picture": picture})

        data: dict[str, Any] = self.post(
            f"{self.protocol}://{self.domain}/dbconnections/signup", data=body
        )
        return data

    def change_password(
        self,
        email: str,
        connection: str,
        password: str | None = None,
        organization: str | None = None,
    ) -> str:
        """Asks to change a password for a given user.

        email (str): The user's email address.

        connection (str): The name of the database connection where this user should be created.

        organization (str, optional): The id of the Organization associated with the user.
        """
        body = {
            "client_id": self.client_id,
            "email": email,
            "connection": connection,
        }
        if organization:
            body["organization"] = organization

        data: str = self.post(
            f"{self.protocol}://{self.domain}/dbconnections/change_password",
            data=body,
        )
        return data