File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 12
12
VideoGrant ,
13
13
ConversationsGrant ,
14
14
TaskRouterGrant ,
15
- ChatGrant
15
+ ChatGrant ,
16
+ PlaybackGrant ,
16
17
)
17
18
18
19
ACCOUNT_SID = 'AC123'
@@ -242,6 +243,22 @@ def test_task_router_grant(self):
242
243
'role' : 'worker'
243
244
}, decoded_token .payload ['grants' ]['task_router' ])
244
245
246
+ def test_playback_grant (self ):
247
+ """Test that PlaybackGrants are created and decoded correctly."""
248
+ grant = {
249
+ 'requestCredentials' : None ,
250
+ 'playbackUrl' : 'https://000.us-east-1.playback.live-video.net/api/video/v1/us-east-000.channel.000?token=xxxxx' ,
251
+ 'playerStreamerSid' : 'VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
252
+ }
253
+ scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
254
+ scat .add_grant (PlaybackGrant (grant = grant ))
255
+ token = scat .to_jwt ()
256
+ assert_is_not_none (token )
257
+ decoded_token = AccessToken .from_jwt (token , 'secret' )
258
+ self ._validate_claims (decoded_token .payload )
259
+ assert_equal (1 , len (decoded_token .payload ['grants' ]))
260
+ assert_equal (grant , decoded_token .payload ['grants' ]['player' ])
261
+
245
262
def test_pass_grants_in_constructor (self ):
246
263
grants = [
247
264
VideoGrant (),
Original file line number Diff line number Diff line change @@ -196,3 +196,20 @@ def to_payload(self):
196
196
grant ['role' ] = self .role
197
197
198
198
return grant
199
+
200
+
201
+ class PlaybackGrant (AccessTokenGrant ):
202
+ """Grant to access Twilio Live stream"""
203
+
204
+ def __init__ (self , grant = None ):
205
+ """Initialize a PlaybackGrant with a grant retrieved from the Twilio API."""
206
+ self .grant = grant
207
+
208
+ @property
209
+ def key (self ):
210
+ """Return the grant's key."""
211
+ return "player"
212
+
213
+ def to_payload (self ):
214
+ """Return the grant."""
215
+ return self .grant
You can’t perform that action at this time.
0 commit comments