8000 feat: Add PlaybackGrant. (#576) · twilio/twilio-python@45a2362 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit 45a2362

Browse files
feat: Add PlaybackGrant. (#576)
* Add PlaybackGrant.
1 parent 2fb3884 commit 45a2362

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

‎< 8000 !-- -->tests/unit/jwt/test_access_token.py

Lines changed: 18 additions & 1 deletion
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,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(),

twilio/jwt/access_token/grants.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)
0