8000 Add PlaybackGrant. · twilio/twilio-python@cef162c · GitHub
[go: up one dir, main page]

Skip to content

Commit cef162c

Browse files
author
Sarah Stringer
committed
Add PlaybackGrant.
1 parent 2fb3884 commit cef162c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/unit/jwt/test_access_token.py

Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
VideoGrant,
1313
ConversationsGrant,
1414
TaskRouterGrant,
15-
ChatGrant
15+
ChatGrant,
16+
PlaybackGrant,
1617
)
1718

1819
ACCOUNT_SID = 'AC123'
@@ -242,6 +243,21 @@ def test_task_router_grant(self):
242243
'role': 'worker'
243244
}, decoded_token.payload['grants']['task_router'])
244245

246+
def test_playback_grant(self):
247+
grant = {
248+
'requestCredentials': None,
249+
'playbackUrl': 'https://000.us-east-1.playback.live-video.net/api/video/v1/us-east-000.channel.000?token=xxxxx',
250+
'playerStreamerSid': 'VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
251+
}
252+
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
253+
scat.add_grant(PlaybackGrant(grant=grant))
254+
token = scat.to_jwt()
255+
assert_is_not_none(token)
256+
decoded_token = AccessToken.from_jwt(token, 'secret')
257+
self._validate_claims(decoded_token.payload)
258+
assert_equal(1, len(decoded_token.payload['grants']))
259+
assert_equal(grant, decoded_token.payload['grants']['player'])
260+
245261
def test_pass_grants_in_constructor(self):
246262
grants = [
247263
VideoGrant(),

twilio/jwt/access_token/grants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,16 @@ 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+
def __init__(self, grant=None):
204+
self.grant = grant
205+
206+
@property
207+
def key(self):
208+
return "player"
209+
210+
def to_payload(self):
211+
return self.grant

0 commit comments

Comments
 (0)
0