8000 Merge pull request #280 from sroyc/master · PNPtutorials/twilio-python@a73f0cc · GitHub
[go: up one dir, main page]

Skip to content

Commit a73f0cc

Browse files
authored
Merge pull request twilio#280 from sroyc/master
Add VideoGrant.
2 parents d77e1f6 + bf588f8 commit a73f0cc

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

tests/test_access_token.py

Lines changed: 17 additions & 2 deletions
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.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, VoiceGrant
7+
from twilio.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, VoiceGrant, VideoGrant
88

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

96+
def test_video_grant(self):
97+
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
98+
scat.add_grant(VideoGrant(configuration_profile_sid='CP123'))
99+
100+
token = str(scat)
101+
assert_is_not_none(token)
102+
payload = decode(token, 'secret')
103+
self._validate_claims(payload)
104+
assert_equal(1, len(payload['grants']))
105+
assert_equal({
106+
'configuration_profile_sid': 'CP123'
107+
}, payload['grants']['video'])
108+
96109
def test_grants(self):
97110
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
98111
scat.add_grant(ConversationsGrant())
99112
scat.add_grant(IpMessagingGrant())
113+
scat.add_grant(VideoGrant())
100114

101115
token = str(scat)
102116
assert_is_not_none(token)
103117
payload = decode(token, 'secret')
104118
self._validate_claims(payload)
105-
assert_equal(2, len(payload['grants']))
119+
assert_equal(3, len(payload['grants']))
106120
assert_equal({}, payload['grants']['rtc'])
107121
assert_equal({}, payload['grants']['ip_messaging'])
122+
assert_equal({}, payload['grants']['video'])
108123

109124
def test_programmable_voice_grant(self):
110125
grant = VoiceGrant(

twilio/access_token.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ def to_payload(self):
8585
return grant
8686

8787

88+
class VideoGrant(object):
89+
""" Grant to access Twilio Video """
90+
def __init__(self, configuration_profile_sid=None):
91+
self.configuration_profile_sid = configuration_profile_sid
92+
93+
@property
94+
def key(self):
95+
return "video"
96+
97+
def to_payload(self):
98+
grant = {}
99+
if self.configuration_profile_sid:
100+
grant['configuration_profile_sid'] = self.configuration_profile_sid
101+
102+
return grant
103+
104+
88105
class AccessToken(object):
89106
""" Access Token used to access Twilio Resources """
90107
def __init__(self, account_sid, signing_key_sid, secret,

0 commit comments

Comments
 (0)
0