Skip to content

Commit 901752e

Browse files
author
Evan Sims
authored
Merge pull request #313 from auth0/sdks-3179/branding-endpoints
[SDK-3179] Add /api/v2/branding endpoints support
2 parents f15520b + ac75e7e commit 901752e

2 files changed

Lines changed: 171 additions & 0 deletions

File tree

auth0/v3/management/branding.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from .rest import RestClient
2+
3+
4+
class Branding(object):
5+
"""Auth0 Branding endpoints
6+
7+
Args:
8+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
9+
10+
token (str): Management API v2 Token
11+
12+
telemetry (bool, optional): Enable or disable Telemetry
13+
(defaults to True)
14+
15+
timeout (float or tuple, optional): Change the requests
16+
connect and read timeout. Pass a tuple to specify
17+
both values separately or a float to set both to it.
18+
(defaults to 5.0 for both)
19+
20+
rest_options (RestClientOptions): Pass an instance of
21+
RestClientOptions to configure additional RestClient
22+
options, such as rate-limit retries.
23+
(defaults to None)
24+
"""
25+
26+
def __init__(
27+
self,
28+
domain,
29+
token,
30+
telemetry=True,
31+
timeout=5.0,
32+
protocol="https",
33+
rest_options=None,
34+
):
35+
self.domain = domain
36+
self.protocol = protocol
37+
self.client = RestClient(
38+
jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options
39+
)
40+
41+
def _url(self, *args):
42+
url = "{}://{}/api/v2/branding".format(self.protocol, self.domain)
43+
for p in args:
44+
if p is not None:
45+
url = "{}/{}".format(url, p)
46+
return url
47+
48+
def get(self, aud=None):
49+
"""Retrieve branding settings. Requires "read:branding" scope.
50+
51+
See: https://auth0.com/docs/api/management/v2#!/Branding/get_branding
52+
"""
53+
54+
return self.client.get(self._url())
55+
56+
def update(self, body):
57+
"""Update branding settings. Requires "update:branding" scope.
58+
59+
Args:
60+
body (dict): Attributes for the updated trigger binding.
61+
62+
See: https://auth0.com/docs/api/management/v2#!/Branding/patch_branding
63+
"""
64+
65+
return self.client.patch(self._url(), data=body)
66+
67+
def get_template_universal_login(self):
68+
"""Get template for New Universal Login Experience. Requires "read:branding" scope.
69+
70+
See: https://auth0.com/docs/api/management/v2#!/Branding/get_universal_login
71+
"""
72+
73+
return self.client.get(self._url("templates", "universal-login"))
74+
75+
def delete_template_universal_login(self):
76+
"""Delete template for New Universal Login Experience. Requires "delete:branding" scope.
77+
78+
See: https://auth0.com/docs/api/management/v2#!/Branding/delete_universal_login
79+
"""
80+
81+
return self.client.delete(self._url("templates", "universal-login"))
82+
83+
def update_template_universal_login(self, body):
84+
"""Update template for New Universal Login Experience. Requires "update:branding" scope.
85+
86+
Args:
87+
body (str): Complete HTML content to assign to the template. See linked API documentation for example.
88+
89+
See: https://auth0.com/docs/api/management/v2#!/Branding/put_universal_login
90+
"""
91+
92+
return self.client.put(
93+
self._url("templates", "universal-login"),
94+
type="put_universal-login_body",
95+
body={"template": body},
96+
)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import unittest
2+
3+
import mock
4+
5+
from ...management.branding import Branding
6+
7+
8+
class TestBranding(unittest.TestCase):
9+
def test_init_with_optionals(self):
10+
branding = Branding(
11+
domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2)
12+
)
13+
self.assertEqual(branding.client.options.timeout, (10, 2))
14+
15+
telemetry = branding.client.base_headers.get("Auth0-Client", None)
16+
self.assertEqual(telemetry, None)
17+
18+
@mock.patch("auth0.v3.management.branding.RestClient")
19+
def test_get(self, mock_rc):
20+
api = mock_rc.return_value
21+
22+
branding = Branding(domain="domain", token="jwttoken")
23+
branding.get()
24+
25+
api.get.assert_called_with(
26+
"https://domain/api/v2/branding",
27+
)
28+
29+
@mock.patch("auth0.v3.management.branding.RestClient")
30+
def test_update(self, mock_rc):
31+
api = mock_rc.return_value
32+
api.patch.return_value = {}
33+
34+
branding = Branding(domain="domain", token="jwttoken")
35+
branding.update({"a": "b", "c": "d"})
36+
37+
api.patch.assert_called_with(
38+
"https://domain/api/v2/branding", data={"a": "b", "c": "d"}
39+
)
40+
41+
@mock.patch("auth0.v3.management.branding.RestClient")
42+
def test_get_template_universal_login(self, mock_rc):
43+
api = mock_rc.return_value
44+
45+
branding = Branding(domain="domain", token="jwttoken")
46+
branding.get_template_universal_login()
47+
48+
api.get.assert_called_with(
49+
"https://domain/api/v2/branding/templates/universal-login",
50+
)
51+
52+
@mock.patch("auth0.v3.management.branding.RestClient")
53+
def test_delete_template_universal_login(self, mock_rc):
54+
api = mock_rc.return_value
55+
56+
branding = Branding(domain="domain", token="jwttoken")
57+
branding.delete_template_universal_login()
58+
59+
api.delete.assert_called_with(
60+
"https://domain/api/v2/branding/templates/universal-login",
61+
)
62+
63+
@mock.patch("auth0.v3.management.branding.RestClient")
64+
def test_update_template_universal_login(self, mock_rc):
65+
api = mock_rc.return_value
66+
api.put.return_value = {}
67+
68+
branding = Branding(domain="domain", token="jwttoken")
69+
branding.update_template_universal_login({"a": "b", "c": "d"})
70+
71+
api.put.assert_called_with(
72+
"https://domain/api/v2/branding/templates/universal-login",
73+
type="put_universal-login_body",
74+
body={"template": {"a": "b", "c": "d"}},
75+
)

0 commit comments

Comments
 (0)