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

Skip to content

Add Sync Grant. #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tests/unit/jwt/test_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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())
Expand Down
20 changes: 20 additions & 0 deletions twilio/jwt/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down