8000 Add Sync Grant. · robscc/twilio-python@1541fb2 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit 1541fb2

Browse files
author
Andres Jaan Tack
committed
Add Sync Grant.
1 parent ffcc28e commit 1541fb2

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

tests/unit/jwt/test_access_token.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from datetime import datetime
55
from nose.tools import assert_equal
66
from twilio.jwt import decode
7-
from twilio.jwt.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, VoiceGrant
7+
from twilio.jwt.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, SyncGrant, VoiceGrant
88

99
ACCOUNT_SID = 'AC123'
1010
SIGNING_KEY_SID = 'SK123'
@@ -93,6 +93,22 @@ def test_ip_messaging_grant(self):
9393
'push_credential_sid': 'CR123'
9494
}, payload['grants']['ip_messaging'])
9595

96+
def test_sync_grant(self):
97+
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
98+
scat.identity = "bender"
99+
scat.add_grant(SyncGrant(service_sid='IS123', endpoint_id='blahblahendpoint'))
100+
101+
token = str(scat)
102+
assert_is_not_none(token)
103+
payload = decode(token, 'secret')
104+
self._validate_claims(payload)
105+
assert_equal(2, len(payload['grants']))
106+
assert_equal("bender", payload['grants']['identity'])
107+
assert_equal({
108+
'service_sid': 'IS123',
109+
'endpoint_id': 'blahblahendpoint'
110+
}, payload['grants']['data_sync'])
111+
96112
def test_grants(self):
97113
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
98114
scat.add_grant(ConversationsGrant())

twilio/jwt/access_token.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ def to_payload(self):
3030
return grant
3131

3232

33+
class SyncGrant(object):
34+
""" Grant to access Twilio Sync """
35+
def __init__(self, service_sid=None, endpoint_id=None):
36+
self.service_sid = service_sid
37+
self.endpoint_id = endpoint_id
38+
39+
@property
40+
def key(self):
41+
return "data_sync"
42+
43+
def to_payload(self):
44+
grant = {}
45+
if self.service_sid:
46+
grant['service_sid'] = self.service_sid
47+
if self.endpoint_id:
48+
grant['endpoint_id'] = self.endpoint_id
49+
50+
527E return grant
51+
52+
3353
class ConversationsGrant(object):
3454
""" Grant to access Twilio Conversations """
3555
def __init__(self, configuration_profile_sid=None):

0 commit comments

Comments
 (0)
0