Skip to content

Commit 0b01ca6

Browse files
author
Nick Zetzl
committed
added support for self service profiles
Signed-off-by: Nick Zetzl <[email protected]>
1 parent 49b8be4 commit 0b01ca6

File tree

7 files changed

+234
-2
lines changed

7 files changed

+234
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ For more code samples on how to integrate the auth0-python SDK in your Python ap
120120
- Roles() ( `Auth0().roles` )
121121
- RulesConfigs() ( `Auth0().rules_configs` )
122122
- Rules() ( `Auth0().rules` )
123+
- SelfServiceProfiles() ( `Auth0().self_service_profiles` )
123124
- Stats() ( `Auth0().stats` )
124125
- Tenants() ( `Auth0().tenants` )
125126
- Tickets() ( `Auth0().tickets` )

auth0/management/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .roles import Roles
2323
from .rules import Rules
2424
from .rules_configs import RulesConfigs
25+
from .self_service_profiles import SelfServiceProfiles
2526
from .stats import Stats
2627
from .tenants import Tenants
2728
from .tickets import Tickets
@@ -59,6 +60,7 @@
5960
"Roles",
6061
"RulesConfigs",
6162
"Rules",
63+
"SelfServiceProfiles",
6264
"Stats",
6365
"Tenants",
6466
"Tickets",

auth0/management/auth0.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .roles import Roles
2727
from .rules import Rules
2828
from .rules_configs import RulesConfigs
29+
from .self_service_profiles import SelfServiceProfiles
2930
from .stats import Stats
3031
from .tenants import Tenants
3132
from .tickets import Tickets
@@ -86,6 +87,9 @@ def __init__(
8687
self.roles = Roles(domain, token, rest_options=rest_options)
8788
self.rules_configs = RulesConfigs(domain, token, rest_options=rest_options)
8889
self.rules = Rules(domain, token, rest_options=rest_options)
90+
self.self_service_profiles = SelfServiceProfiles(
91+
domain, token, rest_options=rest_options
92+
)
8993
self.stats = Stats(domain, token, rest_options=rest_options)
9094
self.tenants = Tenants(domain, token, rest_options=rest_options)
9195
self.tickets = Tickets(domain, token, rest_options=rest_options)
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
from __future__ import annotations
2+
3+
from typing import Any, List # List is being used as list is already a method.
4+
5+
from ..rest import RestClient, RestClientOptions
6+
from ..types import TimeoutType
7+
8+
9+
class SelfServiceProfiles:
10+
"""Auth0 Self Service Profiles endpoints
11+
12+
Args:
13+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
14+
15+
token (str): Management API v2 Token
16+
17+
telemetry (bool, optional): Enable or disable Telemetry
18+
(defaults to True)
19+
20+
timeout (float or tuple, optional): Change the requests
21+
connect and read timeout. Pass a tuple to specify
22+
both values separately or a float to set both to it.
23+
(defaults to 5.0 for both)
24+
25+
protocol (str, optional): Protocol to use when making requests.
26+
(defaults to "https")
27+
28+
rest_options (RestClientOptions): Pass an instance of
29+
RestClientOptions to configure additional RestClient
30+
options, such as rate-limit retries.
31+
(defaults to None)
32+
"""
33+
34+
def __init__(
35+
self,
36+
domain: str,
37+
token: str,
38+
telemetry: bool = True,
39+
timeout: TimeoutType = 5.0,
40+
protocol: str = "https",
41+
rest_options: RestClientOptions | None = None,
42+
) -> None:
43+
self.domain = domain
44+
self.protocol = protocol
45+
self.client = RestClient(
46+
jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options
47+
)
48+
49+
def _url(self, profile_id: str | None = None) -> str:
50+
url = f"{self.protocol}://{self.domain}/api/v2/self-service-profiles"
51+
if id is not None:
52+
return f"{url}/{profile_id}"
53+
return url
54+
55+
def list(
56+
self,
57+
page: int = 0,
58+
per_page: int = 25,
59+
include_totals: bool = True,
60+
) -> List[dict[str, Any]]:
61+
"""List self-service profiles.
62+
63+
Args:
64+
page (int, optional): The result's page number (zero based). By default,
65+
retrieves the first page of results.
66+
67+
per_page (int, optional): The amount of entries per page. By default,
68+
retrieves 25 results per page.
69+
70+
include_totals (bool, optional): True if the query summary is
71+
to be included in the result, False otherwise. Defaults to True.
72+
73+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/get-self-service-profiles
74+
"""
75+
76+
params = {
77+
"page": page,
78+
"per_page": per_page,
79+
"include_totals": str(include_totals).lower(),
80+
}
81+
82+
return self.client.get(self._url(), params=params)
83+
84+
def create(self, body: dict[str, Any]) -> dict[str, Any]:
85+
"""Create a new self-service profile.
86+
87+
Args:
88+
body (dict): Attributes for the new self-service profile.
89+
90+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/post-self-service-profiles
91+
"""
92+
93+
return self.client.post(self._url(), data=body)
94+
95+
def get(self, profile_id: str) -> dict[str, Any]:
96+
"""Get a self-service profile.
97+
98+
Args:
99+
id (str): The id of the self-service profile to retrieve.
100+
101+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/get-self-service-profiles-by-id
102+
"""
103+
104+
return self.client.get(self._url(profile_id))
105+
106+
def delete(self, profile_id: str) -> None:
107+
"""Delete a self-service profile.
108+
109+
Args:
110+
id (str): The id of the self-service profile to delete.
111+
112+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/delete-self-service-profiles-by-id
113+
"""
114+
115+
self.client.delete(self._url(profile_id))
116+
117+
def update(self, profile_id: str, body: dict[str, Any]) -> dict[str, Any]:
118+
"""Update a self-service profile.
119+
120+
Args:
121+
id (str): The id of the self-service profile to update.
122+
123+
body (dict): Attributes of the self-service profile to modify.
124+
125+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/patch-self-service-profiles-by-id
126+
"""
127+
128+
return self.client.patch(self._url(profile_id), data=body)
129+
130+
def get_custom_text(
131+
self, profile_id: str, language: str, page: str
132+
) -> dict[str, Any]:
133+
"""Get the custom text for a self-service profile.
134+
135+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/get-self-service-profile-custom-text
136+
"""
137+
138+
url = self._url(f"{profile_id}/custom-text/{language}/{page}")
139+
return self.client.get(url)
140+
141+
def update_custom_text(
142+
self, profile_id: str, language: str, page: str, body: dict[str, Any]
143+
) -> dict[str, Any]:
144+
"""Update the custom text for a self-service profile.
145+
146+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/put-self-service-profile-custom-text
147+
"""
148+
149+
url = self._url(f"{profile_id}/custom-text/{language}/{page}")
150+
return self.client.put(url, data=body)
151+
152+
def create_sso_ticket(
153+
self, profile_id: str, body: dict[str, Any]
154+
) -> dict[str, Any]:
155+
"""Create a single sign-on ticket for a self-service profile.
156+
157+
Args:
158+
id (str): The id of the self-service profile to create the ticket for.
159+
160+
body (dict): Attributes for the single sign-on ticket.
161+
162+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/post-sso-ticket
163+
"""
164+
165+
url = self._url(f"{profile_id}/sso-ticket")
166+
return self.client.post(url, data=body)
167+
168+
def revoke_sso_ticket(self, profile_id: str, ticket_id: str) -> None:
169+
"""Revoke a single sign-on ticket for a self-service profile.
170+
171+
Args:
172+
id (str): The id of the self-service profile to revoke the ticket from.
173+
174+
ticket (str): The ticket to revoke.
175+
176+
See: https://auth0.com/docs/api/management/v2/self-service-profiles/post-revoke
177+
"""
178+
179+
url = self._url(f"{profile_id}/sso-ticket/{ticket_id}/revoke")
180+
self.client.post(url)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
from unittest import mock
3+
4+
from ...management.self_service_profiles import SelfServiceProfiles
5+
6+
7+
class TestSelfServiceProfiles(unittest.TestCase):
8+
def test_init_with_optionals(self):
9+
t = SelfServiceProfiles(
10+
domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2)
11+
)
12+
self.assertEqual(t.client.options.timeout, (10, 2))
13+
telemetry_header = t.client.base_headers.get("Auth0-Client", None)
14+
self.assertEqual(telemetry_header, None)
15+
16+
@mock.patch("auth0.management.self_service_profiles.RestClient")
17+
def test_list(self, mock_rc):
18+
mock_instance = mock_rc.return_value
19+
20+
s = SelfServiceProfiles(domain="domain", token="jwttoken")
21+
s.list()
22+
23+
args, kwargs = mock_instance.get.call_args
24+
25+
self.assertEqual(args[0], "https://domain/api/v2/self-service-profiles")
26+
self.assertEqual(
27+
kwargs["params"], {"page": 0, "per_page": 25, "include_totals": "true"}
28+
)
29+
30+
s.list(page=1, per_page=50, include_totals=False)
31+
32+
args, kwargs = mock_instance.get.call_args
33+
34+
self.assertEqual(args[0], "https://domain/api/v2/self-service-profiles")
35+
self.assertEqual(
36+
kwargs["params"], {"page": 1, "per_page": 50, "include_totals": "false"}
37+
)

docs/source/management.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ management.rules module
177177
:undoc-members:
178178
:show-inheritance:
179179

180+
management.self_service_profiles module
181+
--------------------------
182+
183+
.. automodule:: auth0.management.self_service_profiles
184+
:members:
185+
:undoc-members:
186+
:show-inheritance:
187+
180188
management.stats module
181189
--------------------------
182190

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
22
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
3-
build-backend = "poetry_dynamic_versioning.backend"
3+
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "auth0-python"
7-
version = "0.0.0" # This is replaced by dynamic versioning
7+
version = "0.0.1" # This is replaced by dynamic versioning
88
description = ""
99
authors = ["Auth0 <[email protected]>"]
1010
license = "MIT"

0 commit comments

Comments
 (0)