Skip to content

Commit b037310

Browse files
Add support for set_url_signature in AuthToken
1 parent 2db58e3 commit b037310

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

cloudinary/auth_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def generate(url=None, acl=None, start_time=None, duration=None,
14-
expiration=None, ip=None, key=None, token_name=AUTH_TOKEN_NAME):
14+
expiration=None, ip=None, key=None, token_name=AUTH_TOKEN_NAME, **_):
1515

1616
if expiration is None:
1717
if duration is not None:

cloudinary/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def cloudinary_url(source, **options):
820820
transformation = re.sub(r'([^:])/+', r'\1/', transformation)
821821

822822
signature = None
823-
if sign_url and not auth_token:
823+
if sign_url and (not auth_token or auth_token.pop('set_url_signature', False)):
824824
to_sign = "/".join(__compact([transformation, source_to_sign]))
825825
if long_url_signature:
826826
# Long signature forces SHA256

test/test_auth_token.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def test_explicit_authToken_should_override_global_setting(self):
6464
"w_300/sample.jpg?__cld_token__=st=222222222~exp=222222322~hmac"
6565
"=55cfe516530461213fe3b3606014533b1eca8ff60aeab79d1bb84c9322eebc1f")
6666

67+
def test_should_set_url_signature(self):
68+
cloudinary.config(private_cdn=True)
69+
url, _ = cloudinary.utils.cloudinary_url("sample.jpg", sign_url=True,
70+
auth_token={"key": ALT_KEY, "start_time": 222222222, "duration": 100,
71+
"set_url_signature": True},
72+
type="authenticated", transformation={"crop": "scale", "width": 300})
73+
self.assertEqual("http://test123-res.cloudinary.com/image/authenticated/s--Ok4O32K7--/"
74+
"c_scale,w_300/sample.jpg?__cld_token__=st=222222222~exp=222222322~hmac"
75+
"=92a55aaed531b2dab074074bbd1430120119f9cb1b901656925dda2e514a63cc", url)
76+
6777
def test_should_compute_expiration_as_start_time_plus_duration(self):
6878
cloudinary.config(private_cdn=True)
6979
token = {"key": KEY, "start_time": 11111111, "duration": 300}
@@ -75,8 +85,7 @@ def test_should_compute_expiration_as_start_time_plus_duration(self):
7585

7686
def test_generate_token_string(self):
7787
user = "foobar" # we can't rely on the default "now" value in tests
78-
token_options = {"key": KEY, "duration": 300, "acl": "/*/t_%s" % user}
79-
token_options["start_time"] = 222222222 # we can't rely on the default "now" value in tests
88+
token_options = {"key": KEY, "duration": 300, "acl": "/*/t_%s" % user, "start_time": 222222222}
8089
cookie_token = cloudinary.utils.generate_auth_token(**token_options)
8190
self.assertEqual(
8291
cookie_token,
@@ -97,8 +106,8 @@ def test_should_ignore_url_if_acl_is_provided(self):
97106
)
98107

99108
def test_should_support_multiple_acls(self):
100-
token_options = {"key": KEY, "duration": 3600,
101-
"acl": ["/i/a/*", "/i/a/*", "/i/a/*"],
109+
token_options = {"key": KEY, "duration": 3600,
110+
"acl": ["/i/a/*", "/i/a/*", "/i/a/*"],
102111
"start_time": 222222222}
103112

104113
cookie_token = cloudinary.utils.generate_auth_token(**token_options)
@@ -128,6 +137,5 @@ def test_should_support_url_without_acl(self):
128137
)
129138

130139

131-
132140
if __name__ == '__main__':
133141
unittest.main()

0 commit comments

Comments
 (0)