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 11
11
VoiceGrant ,
12
12
VideoGrant ,
13
13
ConversationsGrant ,
14
- TaskRouterGrant
14
+ TaskRouterGrant ,
15
+ ChatGrant
15
16
)
16
17
17
18
ACCOUNT_SID = 'AC123'
@@ -121,6 +122,20 @@ def test_ip_messaging_grant(self):
121
122
'push_credential_sid' : 'CR123'
122
123
}, decoded_token .payload ['grants' ]['ip_messaging' ])
123
124
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
+
124
139
def test_sync_grant (self ):
125
140
scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
126
141
scat .identity = "bender"
Original file line number Diff line number Diff line change @@ -18,8 +18,38 @@ def new_func(*args, **kwargs):
18
18
return new_func
19
19
20
20
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
+
21
49
class IpMessagingGrant (AccessTokenGrant ):
22
50
"""Grant to access Twilio IP Messaging"""
51
+
52
+ @deprecated
23
53
def __init__ (self , service_sid = None , endpoint_id = None ,
24
54
deployment_role_sid = None , push_credential_sid = None ):
25
55
self .service_sid = service_sid
You can’t perform that action at this time.
0 commit comments