8000 add back deprecated conversations grant · jstacoder/twilio-python@7201d43 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7201d43

Browse files
author
Jozsef Vass
committed
add back deprecated conversations grant
1 parent 47c383d commit 7201d43

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

tests/unit/jwt/test_access_token.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
SyncGrant,
1111
VoiceGrant,
1212
VideoGrant,
13+
ConversationsGrant,
1314
TaskRouterGrant
1415
)
1516

@@ -80,17 +81,30 @@ def test_identity(self):
8081
'identity': 'test@twilio.com'
8182
}, decoded_token.payload['grants'])
8283

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+
8397
def test_video_grant(self):
8498
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
85-
scat.add_grant(VideoGrant(room='CP123'))
99+
scat.add_grant(VideoGrant(room='RM123'))
86100

87101
token = scat.to_jwt()
88102
assert_is_not_none(token)
89103
decoded_token = AccessToken.from_jwt(token, 'secret')
90104
self._validate_claims(decoded_token.payload)
91105
assert_equal(1, len(decoded_token.payload['grants']))
92106
assert_equal({
93-
'room': 'CP123'
107+
'room': 'RM123'
94108
}, decoded_token.payload['grants']['video'])
95109

96110
def test_ip_messaging_grant(self):

twilio/jwt/access_token/grants.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
from twilio.jwt.access_token import AccessTokenGrant
2+
import warnings
3+
import functools
4+
5+
6+
def deprecated(func):
7+
'''This is a decorator which can be used to mark functions
8+
as deprecated. It will result in a warning being emitted
9+
when the function is used.'''
10+
11+
@functools.wraps(func)
12+
def new_func(*args, **kwargs):
13+
warnings.warn_explicit(
14+
"Call to deprecated function {}.".format(func.__name__),
15+
category=DeprecationWarning,
16+
filename=func.func_code.co_filename,
17+
lineno=func.func_code.co_firstlineno + 1
18+
)
19+
return func(*args, **kwargs)
20+
return new_func
221

322

423
class IpMessagingGrant(AccessTokenGrant):
@@ -86,6 +105,24 @@ def to_payload(self):
86105
return grant
87106

88107

108+
class ConversationsGrant(AccessTokenGrant):
109+
"""Grant to access Twilio Conversations"""
110+
@deprecated
111+
def __init__(self, configuration_profile_sid=None):
112+
self.configuration_profile_sid = configuration_profile_sid
113+
114+
@property
115+
def key(self):
116+
return "rtc"
117+
118+
def to_payload(self):
119+
grant = {}
120+
if self.configuration_profile_sid:
121+
grant['configuration_profile_sid'] = self.configuration_profile_sid
122+
123+
return grant
124+
125+
89126
class VideoGrant(AccessTokenGrant):
90127
"""Grant to access Twilio Video"""
91128
def __init__(self, room=None):

0 commit comments

Comments
 (0)
0