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 profile_id is not None :
52+ return f"{ url } /{ profile_id } "
53+ return url
54+
55+ def all (
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 )
0 commit comments