File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1111 VoiceGrant ,
1212 VideoGrant ,
1313 ConversationsGrant ,
14- TaskRouterGrant
14+ TaskRouterGrant ,
15+ ChatGrant
1516)
1617
1718ACCOUNT_SID = 'AC123'
@@ -121,6 +122,20 @@ def test_ip_messaging_grant(self):
121122 'push_credential_sid' : 'CR123'
122123 }, decoded_token .payload ['grants' ]['ip_messaging' ])
123124
125+ def test_chat_grant (self ):
126+ scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
127+ scat .add_grant (ChatGrant (service_sid = 'IS123' , push_credential_sid = 'CR123' ))
128+
129+ token = scat .to_jwt ()
130+ assert_is_not_none (token )
131+ decoded_token = AccessToken .from_jwt (token , 'secret' )
132+ self ._validate_claims (decoded_token .payload )
133+ assert_equal (1 , len (decoded_token .payload ['grants' ]))
134+ assert_equal ({
135+ 'service_sid' : 'IS123' ,
136+ 'push_credential_sid' : 'CR123'
137+ }, decoded_token .payload ['grants' ]['chat' ])
138+
124139 def test_sync_grant (self ):
125140 scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
126141 scat .identity = "bender"
Original file line number Diff line number Diff line change @@ -18,8 +18,38 @@ def new_func(*args, **kwargs):
1818 return new_func
1919
2020
21+ class ChatGrant (AccessTokenGrant ):
22+ """Grant to access Twilio Chat"""
23+
24+ def __init__ (self , service_sid = None , endpoint_id = None ,
25+ deployment_role_sid = None , push_credential_sid = None ):
26+ self .service_sid = service_sid
27+ self .endpoint_id = endpoint_id
28+ self .deployment_role_sid = deployment_role_sid
29+ self .push_credential_sid = push_credential_sid
30+
31+ @property
32+ def key (self ):
33+ return "chat"
34+
35+ def to_payload (self ):
36+ grant = {}
37+ if self .service_sid :
38+ grant ['service_sid' ] = self .service_sid
39+ if self .endpoint_id :
40+ grant ['endpoint_id' ] = self .endpoint_id
41+ if self .deployment_role_sid :
42+ grant ['deployment_role_sid' ] = self .deployment_role_sid
43+ if self .push_credential_sid :
44+ grant ['push_credential_sid' ] = self .push_credential_sid
45+
46+ return grant
47+
48+
2149class IpMessagingGrant (AccessTokenGrant ):
2250 """Grant to access Twilio IP Messaging"""
51+
52+ @deprecated
2353 def __init__ (self , service_sid = None , endpoint_id = None ,
2454 deployment_role_sid = None , push_credential_sid = None ):
2555 self .service_sid = service_sid
You can’t perform that action at this time.
0 commit comments