diff --git a/tests/unit/jwt/test_access_token.py b/tests/unit/jwt/test_access_token.py index 13619e726d..1753e46730 100644 --- a/tests/unit/jwt/test_access_token.py +++ b/tests/unit/jwt/test_access_token.py @@ -4,7 +4,7 @@ from datetime import datetime from nose.tools import assert_equal from twilio.jwt import decode -from twilio.jwt.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, VoiceGrant +from twilio.jwt.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, SyncGrant, VoiceGrant ACCOUNT_SID = 'AC123' SIGNING_KEY_SID = 'SK123' @@ -93,6 +93,22 @@ def test_ip_messaging_grant(self): 'push_credential_sid': 'CR123' }, payload['grants']['ip_messaging']) + def test_sync_grant(self): + scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret') + scat.identity = "bender" + scat.add_grant(SyncGrant(service_sid='IS123', endpoint_id='blahblahendpoint')) + + token = str(scat) + assert_is_not_none(token) + payload = decode(token, 'secret') + self._validate_claims(payload) + assert_equal(2, len(payload['grants'])) + assert_equal("bender", payload['grants']['identity']) + assert_equal({ + 'service_sid': 'IS123', + 'endpoint_id': 'blahblahendpoint' + }, payload['grants']['data_sync']) + def test_grants(self): scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret') scat.add_grant(ConversationsGrant()) diff --git a/twilio/jwt/access_token.py b/twilio/jwt/access_token.py index 875c69223b..bb8a1693c8 100644 --- a/twilio/jwt/access_token.py +++ b/twilio/jwt/access_token.py @@ -30,6 +30,26 @@ def to_payload(self): return grant +class SyncGrant(object): + """ Grant to access Twilio Sync """ + def __init__(self, service_sid=None, endpoint_id=None): + self.service_sid = service_sid + self.endpoint_id = endpoint_id + + @property + def key(self): + return "data_sync" + + def to_payload(self): + grant = {} + if self.service_sid: + grant['service_sid'] = self.service_sid + if self.endpoint_id: + grant['endpoint_id'] = self.endpoint_id + + return grant + + class ConversationsGrant(object): """ Grant to access Twilio Conversations """ def __init__(self, configuration_profile_sid=None):