File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212 VideoGrant ,
1313 ConversationsGrant ,
1414 TaskRouterGrant ,
15- ChatGrant
15+ ChatGrant ,
16+ PlaybackGrant ,
1617)
1718
1819ACCOUNT_SID = 'AC123'
@@ -242,6 +243,22 @@ def test_task_router_grant(self):
242243 'role' : 'worker'
243244 }, decoded_token .payload ['grants' ]['task_router' ])
244245
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+
245262 def test_pass_grants_in_constructor (self ):
246263 grants = [
247264 VideoGrant (),
Original file line number Diff line number Diff line change @@ -196,3 +196,20 @@ def to_payload(self):
196196 grant ['role' ] = self .role
197197
198198 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