8000 Update video grant · DropByDrop/twilio-python@3417df8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3417df8

Browse files
committed
Update video grant
1 parent 1fcd2c6 commit 3417df8

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

tests/unit/jwt/test_access_token.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from twilio.jwt.access_token import AccessToken
88
from twilio.jwt.access_token.grants import (
9-
ConversationsGrant,
109
IpMessagingGrant,
1110
SyncGrant,
1211
VoiceGrant,
@@ -80,30 +79,17 @@ def test_identity(self):
8079
'identity': 'test@twilio.com'
8180
}, decoded_token.payload['grants'])
8281

83-
def test_conversations_grant(self):
84-
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
85-
scat.add_grant(ConversationsGrant(configuration_profile_sid='CP123'))
86-
87-
token = scat.to_jwt()
88-
assert_is_not_none(token)
89-
decoded_token = AccessToken.from_jwt(token, 'secret')
90-
self._validate_claims(decoded_token.payload)
91-
assert_equal(1, len(decoded_token.payload['grants']))
92-
assert_equal({
93-
'configuration_profile_sid': 'CP123'
94-
}, decoded_token.payload['grants']['rtc'])
95-
9682
def test_video_grant(self):
9783
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
98-
scat.add_grant(VideoGrant(configuration_profile_sid='CP123'))
84+
scat.add_grant(VideoGrant(room='CP123'))
9985

10086
token = scat.to_jwt()
10187
assert_is_not_none(token)
10288
decoded_token = AccessToken.from_jwt(token, 'secret')
10389
self._validate_claims(decoded_token.payload)
10490
assert_equal(1, len(decoded_token.payload['grants']))
10591
assert_equal({
106-
'configuration_profile_sid': 'CP123'
92+
'room': 'CP123'
10793
}, decoded_token.payload['grants']['video'])
10894

10995
def test_ip_messaging_grant(self):
@@ -138,15 +124,15 @@ def test_sync_grant(self):
138124

139125
def test_grants(self):
140126
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
141-
scat.add_grant(ConversationsGrant())
127+
scat.add_grant(VideoGrant())
142128
scat.add_grant(IpMessagingGrant())
143129

144130
token = scat.to_jwt()
145131
assert_is_not_none(token)
146132
decoded_token = AccessToken.from_jwt(token, 'secret')
147133
self._validate_claims(decoded_token.payload)
148134
assert_equal(2, len(decoded_token.payload['grants']))
149-
assert_equal({}, decoded_token.payload['grants']['rtc'])
135+
assert_equal({}, decoded_token.payload['grants']['video'])
150136
assert_equal({}, decoded_token.payload['grants']['ip_messaging'])
151137

152138
def test_programmable_voice_grant(self):
@@ -176,7 +162,7 @@ def test_programmable_voice_grant(self):
176162

177163
def test_pass_grants_in_constructor(self):
178164
grants = [
179-
ConversationsGrant(),
165+
VideoGrant(),
180166
IpMessagingGrant()
181167
]
182168
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', grants=grants)
@@ -187,15 +173,15 @@ def test_pass_grants_in_constructor(self):
187173
decoded_token = AccessToken.from_jwt(token, 'secret')
188174
self._validate_claims(decoded_token.payload)
189175
assert_equal(2, len(decoded_token.payload['grants']))
190-
assert_equal({}, decoded_token.payload['grants']['rtc'])
176+
assert_equal({}, decoded_token.payload['grants']['video'])
191177
assert_equal({}, decoded_token.payload['grants']['ip_messaging'])
192178

193179
def test_constructor_validates_grants(self):
194-
grants = [ConversationsGrant, 'GrantMeAccessToEverything']
180+
grants = [VideoGrant, 'GrantMeAccessToEverything']
195181
self.assertRaises(ValueError, AccessToken, ACCOUNT_SID, SIGNING_KEY_SID, 'secret',
196182
grants=grants)
197183

198184
def test_add_grant_validates_grant(self):
199185
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
200-
scat.add_grant(ConversationsGrant())
186+
scat.add_grant(VideoGrant())
201187
self.assertRaises(ValueError, scat.add_grant, 'GrantRootAccess')

twilio/jwt/access_token/grants.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,6 @@ def to_payload(self):
4848
return grant
4949

5050

51-
class ConversationsGrant(AccessTokenGrant):
52-
"""Grant to access Twilio Conversations"""
53-
def __init__(self, configuration_profile_sid=None):
54-
self.configuration_profile_sid = configuration_profile_sid
55-
56-
@property
57-
def key(self):
58-
return "rtc"
59-
60-
def to_payload(self):
61-
grant = {}
62-
if self.configuration_profile_sid:
63-
grant['configuration_profile_sid'] = self.configuration_profile_sid
64-
65-
return grant
66-
67-
6851
class VoiceGrant(AccessTokenGrant):
6952
"""Grant to access Twilio Programmable Voice"""
7053
def __init__(self,
@@ -105,16 +88,16 @@ def to_payload(self):
10588

10689
class VideoGrant(AccessTokenGrant):
10790
"""Grant to access Twilio Video"""
108-
def __init__(self, configuration_profile_sid=None):
109-
self.configuration_profile_sid = configuration_profile_sid
91+
def __init__(self, room=None):
92+
self.room = room
11093

11194
@property
11295
def key(self):
11396
return "video"
11497

11598
def to_payload(self):
11699
grant = {}
117-
if self.configuration_profile_sid:
118-
grant['configuration_profile_sid'] = self.configuration_profile_sid
100+
if self.room:
101+
grant['room'] = self.room
119102

120103
return grant

0 commit comments

Comments
 (0)
0