Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add back deprecated conversations grant #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tests/unit/jwt/test_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SyncGrant,
VoiceGrant,
VideoGrant,
ConversationsGrant,
TaskRouterGrant
)

Expand Down Expand Up @@ -80,17 +81,30 @@ def test_identity(self):
'identity': '[email protected]'
}, decoded_token.payload['grants'])

def test_conversations_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(ConversationsGrant(configuration_profile_sid='CP123'))

token = scat.to_jwt()
assert_is_not_none(token)
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert_equal(1, len(decoded_token.payload['grants']))
assert_equal({
'configuration_profile_sid': 'CP123'
}, decoded_token.payload['grants']['rtc'])

def test_video_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(VideoGrant(room='CP123'))
scat.add_grant(VideoGrant(room='RM123'))

token = scat.to_jwt()
assert_is_not_none(token)
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert_equal(1, len(decoded_token.payload['grants']))
assert_equal({
'room': 'CP123'
'room': 'RM123'
}, decoded_token.payload['grants']['video'])

def test_ip_messaging_grant(self):
Expand Down
37 changes: 37 additions & 0 deletions twilio/jwt/access_token/grants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
from twilio.jwt.access_token import AccessTokenGrant
import warnings
import functools


def deprecated(func):
'''This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.'''

@functools.wraps(func)
def new_func(*args, **kwargs):
warnings.warn_explicit(
"Call to deprecated function {}.".format(func.__name__),
category=DeprecationWarning,
filename=func.func_code.co_filename,
lineno=func.func_code.co_firstlineno + 1
)
return func(*args, **kwargs)
return new_func


class IpMessagingGrant(AccessTokenGrant):
Expand Down Expand Up @@ -86,6 +105,24 @@ def to_payload(self):
return grant


class ConversationsGrant(AccessTokenGrant):
"""Grant to access Twilio Conversations"""
@deprecated
def __init__(self, configuration_profile_sid=None):
self.configuration_profile_sid = configuration_profile_sid

@property
def key(self):
return "rtc"

def to_payload(self):
grant = {}
if self.configuration_profile_sid:
grant['configuration_profile_sid'] = self.configuration_profile_sid

return grant


class VideoGrant(AccessTokenGrant):
"""Grant to access Twilio Video"""
def __init__(self, room=None):
Expand Down