Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59bcfa9

Browse files
Annybell VillarroelAnnybell Villarroel
Annybell Villarroel
authored and
Annybell Villarroel
committed
Updating management SDK
1 parent bede616 commit 59bcfa9

File tree

7 files changed

+463
-0
lines changed

7 files changed

+463
-0
lines changed

auth0/v2/management/client_grants.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from .rest import RestClient
2+
3+
4+
class ClientGrants(object):
5+
6+
"""Auth0 client grants endpoints
7+
8+
Args:
9+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
10+
11+
token (str): An API token created with your account's global
12+
keys. You can create one by using the token generator in the
13+
API Explorer: https://auth0.com/docs/api/v2
14+
15+
telemetry (bool, optional): Enable or disable Telemetry
16+
(defaults to True)
17+
"""
18+
19+
def __init__(self, domain, token, telemetry=True):
20+
self.domain = domain
21+
self.client = RestClient(jwt=token, telemetry=telemetry)
22+
23+
def _url(self, id=None):
24+
url = 'https://%s/api/v2/client-grants' % self.domain
25+
if id is not None:
26+
return url + '/' + id
27+
return url
28+
29+
def all(self, audience=None):
30+
"""Retrieves all client grants.
31+
32+
Args:
33+
audience (str, optional): URL Encoded audience of a Resource Server
34+
to filter
35+
"""
36+
37+
params = {'audience': audience or None}
38+
39+
return self.client.get(self._url(), params=params)
40+
41+
def create(self, body):
42+
"""Creates a client grant.
43+
44+
Args:
45+
body (dict): Attributes for the new client grant.
46+
See: https://auth0.com/docs/api/management/v2#!/Client_Grants/post_client_grants
47+
"""
48+
49+
return self.client.post(self._url(), data=body)
50+
51+
def delete(self, id):
52+
"""Deletes a client grant.
53+
54+
Args:
55+
id (str): Id of client to delete.
56+
"""
57+
58+
return self.client.delete(self._url(id))
59+
60+
def update(self, id, body):
61+
"""Modifies a client grant.
62+
63+
Args:
64+
id (str): The id of the client grant to modify.
65+
66+
body (dict): Attributes to modify.
67+
"""
68+
69+
return self.client.patch(self._url(id), data=body)

auth0/v2/management/guardian.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from .rest import RestClient
2+
3+
4+
class Guardian(object):
5+
6+
"""Auth0 guardian endpoints
7+
8+
Args:
9+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
10+
11+
token (str): An API token created with your account's global
12+
keys. You can create one by using the token generator in the
13+
API Explorer: https://auth0.com/docs/api/v2
14+
15+
telemetry (bool, optional): Enable or disable Telemetry
16+
(defaults to True)
17+
"""
18+
19+
def __init__(self, domain, token, telemetry=True):
20+
self.domain = domain
21+
self.client = RestClient(jwt=token, telemetry=telemetry)
22+
23+
def _url(self, id=None):
24+
url = 'https://%s/api/v2/guardian' % self.domain
25+
if id is not None:
26+
return url + '/' + id
27+
return url
28+
29+
def all_factors(self):
30+
"""Retrieves all factors. Useful to check factor enablement and
31+
trial status.
32+
"""
33+
34+
return self.client.get(self._url('factors'))
35+
36+
def update_factor(self, name, body):
37+
"""Update Guardian factor
38+
Useful to enable / disable factor
39+
40+
Args:
41+
name (str): Either push-notification or sms
42+
body (dict): Attributes to modify.
43+
See: https://auth0.com/docs/api/management/v2#!/Guardian/put_factors_by_name
44+
"""
45+
url = self._url('factors/%s' % (name))
46+
return self.client.patch(url, data=body)
47+
48+
def update_templates(self, body):
49+
"""Update enrollment and verification SMS templates.
50+
51+
Useful to send custom messages on sms enrollment and verification
52+
53+
Args:
54+
body (dict): Attributes to modify.
55+
See: https://auth0.com/docs/api/management/v2#!/Guardian/put_templates
56+
"""
57+
58+
return self.client.patch(self._url('factors/sms/templates'), data=body)
59+
60+
def get_templates(self):
61+
"""Get enrollment and verification templates
62+
63+
Retrieve both templates. Useful to check if a different template than
64+
default was set.
65+
"""
66+
67+
return self.client.get(self._url('factors/sms/templates'))
68+
69+
def get_enrollment(self, id):
70+
"""Retrieves an enrollment.
71+
Useful to check its type and related metadata.
72+
73+
Args:
74+
id (str): The id of the device account to update
75+
"""
76+
url = self._url('enrollments/%s' % (id))
77+
return self.client.get(url)
78+
79+
def delete_enrollment(self, id):
80+
"""Deletes an enrollment.
81+
82+
Useful when you want to force re-enroll.
83+
84+
Args:
85+
id (str): The id of the device account to update
86+
"""
87+
url = self._url('enrollments/%s' % (id))
88+
return self.client.delete(url)
89+
90+
def create_enrollment_ticket(self):
91+
"""Creates an enrollment ticket for user_id
92+
93+
A useful way to send an email to a user, with a link that lead to
94+
start the enrollment process
95+
96+
Args:
97+
body (dict): Details of the user to send the ticket to.
98+
See: https://auth0.com/docs/api/management/v2#!/Guardian/post_ticket
99+
"""
100+
return self.client.post(self._url('enrollments/ticket'))
101+
102+
def get_factor_providers(self, factor_name, name):
103+
"""Get Guardian factor providers.
104+
105+
Returns provider configuration
106+
Args:
107+
factor_name (str): Either push-notification or sms
108+
name (str): Name of the provider
109+
"""
110+
url = self._url('factors/%s/providers/%s' % (factor_name, name))
111+
return self.client.get(url)
112+
113+
def update_factor_providers(self, factor_name, name):
114+
"""Get Guardian factor providers.
115+
116+
Returns provider configuration
117+
Args:
118+
factor_name (str): Either push-notification or sms
119+
name (str): Name of the provider
120+
"""
121+
url = self._url('factors/%s/providers/%s' % (factor_name, name))
122+
return self.client.patch(url)

auth0/v2/management/jobs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def get(self, id):
3434
"""
3535
return self.client.get(self._url(id))
3636

37+
def get_failed_job(self, id):
38+
"""Get failed job error details
39+
40+
Args:
41+
id (str): The id of the job.
42+
"""
43+
url = self._url('%s/errors' % (id))
44+
return self.client.get(url)
45+
3746
def import_users(self, connection_id, file_obj):
3847
"""Imports users to a connection from a file.
3948

auth0/v2/management/logs.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from .rest import RestClient
2+
3+
4+
class Logs(object):
5+
6+
"""Auth0 logs endpoints
7+
8+
Args:
9+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
10+
11+
token (str): An API token created with your account's global
12+
keys. You can create one by using the token generator in the
13+
API Explorer: https://auth0.com/docs/api/v2
14+
15+
telemetry (bool, optional): Enable or disable Telemetry
16+
(defaults to True)
17+
"""
18+
19+
def __init__(self, domain, token, telemetry=True):
20+
self.domain = domain
21+
self.client = RestClient(jwt=token, telemetry=telemetry)
22+
23+
def _url(self, id=None):
24+
url = 'https://%s/api/v2/logs' % self.domain
25+
if id is not None:
26+
return url + '/' + id
27+
return url
28+
29+
def search(self, page=0, per_page=25, sort=None, q=None,
30+
include_totals=True, fields=[], from_param=None, take=None,
31+
include_fields=True):
32+
"""Search log events.
33+
34+
Args:
35+
page (int, optional): The result's page number (zero based).
36+
37+
per_page (int, optional): The amount of entries per page.
38+
39+
sort (str, optional): The field to use for sorting.
40+
1 == ascending and -1 == descending. (e.g: date:1)
41+
42+
q (str, optional): Query in Lucene query string syntax.
43+
44+
fields (list of str, optional): A list of fields to include or
45+
exclude from the result (depending on include_fields). Empty to
46+
retrieve all fields.
47+
48+
include_fields (bool, optional): True if the fields specified are
49+
to be include in the result, False otherwise.
50+
51+
include_totals (bool, optional): true if a query summary must be
52+
included in the result, false otherwise. Default false.
53+
54+
from_param (str, optional): Log Event Id to start retrieving logs. You can
55+
limit the amount of logs using the take parameter
56+
57+
take (int, optional): The total amount of entries to retrieve when
58+
using the from parameter.
59+
"""
60+
params = {
61+
'per_page': per_page,
62+
'page': page,
63+
'include_totals': str(include_totals).lower(),
64+
'sort': sort,
65+
'fields': ','.join(fields) or None,
66+
'include_fields': str(include_fields).lower(),
67+
'q': q,
68+
'from': from_param,
69+
'take': take
70+
}
71+
return self.client.get(self._url(), params=params)
72+
73+
def get(self, id):
74+
"""Retrieves the data related to the log entry identified by id.
75+
76+
Args:
77+
id (str): The log_id of the log to retrieve
78+
"""
79+
80+
return self.client.get(self._url(id))
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from .rest import RestClient
2+
3+
4+
class ResourceServers(object):
5+
6+
"""Auth0 resource servers endpoints
7+
8+
Args:
9+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
10+
11+
token (str): An API token created with your account's global
12+
keys. You can create one by using the token generator in the
13+
API Explorer: https://auth0.com/docs/api/v2
14+
15+
telemetry (bool, optional): Enable or disable Telemetry
16+
(defaults to True)
17+
"""
18+
19+
def __init__(self, domain, token, telemetry=True):
20+
self.domain = domain
21+
self.client = RestClient(jwt=token, telemetry=telemetry)
22+
23+
def _url(self, id=None):
24+
url = 'https://%s/api/v2/resource-servers' % self.domain
25+
if id is not None:
26+
return url + '/' + id
27+
return url
28+
29+
def create(self, body):
30+
"""Create a new resource server.
31+
32+
Args:
33+
body (dict): Attributes for the new resource Server
34+
See: https://auth0.com/docs/api/management/v2#!/Resource_Servers/post_resource_servers
35+
"""
36+
37+
return self.client.post(self._url(), data=body)
38+
39+
def get(self, id):
40+
"""Retrieves a resource server by its id.
41+
42+
Args:
43+
id (str): Id of the resource server to get.
44+
"""
45+
46+
return self.client.get(self._url(id))
47+
48+
def delete(self, id):
49+
"""Deletes a resource server.
50+
51+
Args:
52+
id (str): Id of resource server to delete.
53+
"""
54+
55+
return self.client.delete(self._url(id))
56+
57+
def update(self, id, body):
58+
"""Modifies a resource server.
59+
60+
Args:
61+
id (str): The id of the resource server to update.
62+
63+
body (dict): Attributes to modify.
64+
"""
65+
66+
return self.client.patch(self._url(id), data=body)

0 commit comments

Comments
 (0)