8000 Add Video Grant · PNPtutorials/twilio-python@380e624 · GitHub
[go: up one dir, main page]

Skip to content

Commit 380e624

Browse files
committed
Add Video Grant
1 parent cb60c66 commit 380e624

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tests/unit/jwt/test_access_token.py

Lines changed: 14 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, SyncGrant, VoiceGrant
7+
from twilio.jwt.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, SyncGrant, VoiceGrant, VideoGrant
88

99
ACCOUNT_SID = 'AC123'
1010
SIGNING_KEY_SID = 'SK123'
@@ -79,6 +79,19 @@ def test_conversations_grant(self):
7979
'configuration_profile_sid': 'CP123'
8080
}, payload['grants']['rtc'])
8181

82+
def test_video_grant(self):
83+
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
84+
scat.add_grant(VideoGrant(configuration_profile_sid='CP123'))
85+
86+
token = str(scat)
87+
assert_is_not_none(token)
88+
payload = decode(token, 'secret')
89+
self._validate_claims(payload)
90+
assert_equal(1, len(payload['grants']))
91+
assert_equal({
92+
'configuration_profile_sid': 'CP123'
93+
}, payload['grants']['video'])
94+
8295
def test_ip_messaging_grant(self):
8396
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
8497
scat.add_grant(IpMessagingGrant(service_sid='IS123', push_credential_sid='CR123'))

twilio/jwt/access_token.py

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

107107

108+
class VideoGrant(object):
109+
""" Grant to access Twilio Video """
110+
def __init__(self, configuration_profile_sid=None):
111+
self.configuration_profile_sid = configuration_profile_sid
112+
113+
@property
114+
def key(self):
115+
return "video"
116+
117+
def to_payload(self):
118+
grant = {}
119+
if self.configuration_profile_sid:
120+
grant['configuration_profile_sid'] = self.configuration_profile_sid
121+
122+
return grant
123+
124+
108125
class AccessToken(object):
109126
""" Access Token used to access Twilio Resources """
110127
def __init__(self, account_sid, signing_key_sid, secret,

0 commit comments

Comments
 (0)
0