8000 Merge pull request #313 from twilio/next-gen-video-grant · DropByDrop/twilio-python@96dfdda · GitHub
[go: up one dir, main page]

Skip to content

Commit 96dfdda

Browse files
authored
Merge pull request twilio#313 from twilio/next-gen-video-grant
Update video grant
2 parents 7346ebf + 3417df8 commit 96dfdda

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,
@@ -81,30 +80,17 @@ def test_identity(self):
8180
'identity': 'test@twilio.com'
8281
}, decoded_token.payload['grants'])
8382

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

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

11096
def test_ip_messaging_grant(self):
@@ -139,15 +125,15 @@ def test_sync_grant(self):
139125

140126
def test_grants(self):
141127
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
142-
scat.add_grant(ConversationsGrant())
128+
scat.add_grant(VideoGrant())
143129
scat.add_grant(IpMessagingGrant())
144130

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

153139
def test_programmable_voice_grant(self):
@@ -198,7 +184,7 @@ def test_task_router_grant(self):
198184

199185
def test_pass_grants_in_constructor(self):
200186
grants = [
201-
ConversationsGrant(),
187+
VideoGrant(),
202188
IpMessagingGrant()
203189
]
204190
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', grants=grants)
@@ -209,15 +195,15 @@ def test_pass_grants_in_constructor(self):
209195
decoded_token = AccessToken.from_jwt(token, 'secret')
210196
self._validate_claims(decoded_token.payload)
211197
assert_equal(2, len(decoded_token.payload['grants']))
212-
assert_equal({}, decoded_token.payload['grants']['rtc'])
198+
assert_equal({}, decoded_token.payload['grants']['video'])
213199
assert_equal({}, decoded_token.payload['grants']['ip_messaging'])
214200

215201
def test_constructor_validates_grants(self):
216-
grants = [ConversationsGrant, 'GrantMeAccessToEverything']
202+
grants = [VideoGrant, 'GrantMeAccessToEverything']
217203
self.assertRaises(ValueError, AccessToken, ACCOUNT_SID, SIGNING_KEY_SID, 'secret',
218204
grants=grants)
219205

220206
def test_add_grant_validates_grant(self):
221207
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
222-
scat.add_grant(ConversationsGrant())
208+
scat.add_grant(VideoGrant())
223209
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,17 +88,17 @@ 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
121104

0 commit comments

Comments
 (0)
0