Skip to content

Commit 83d7b2f

Browse files
liberty-rowlandcodejudas
authored andcommitted
Add incoming.allow to AccessToken VoiceGrant (#413)
1 parent 451fff5 commit 83d7b2f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/unit/jwt/test_access_token.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,25 @@ def test_programmable_voice_grant(self):
190190
}
191191
}, decoded_token.payload['grants']['voice'])
192192

193+
def test_programmable_voice_grant_incoming(self):
194+
grant = VoiceGrant(
195+
incoming_allow=True
196+
)
197+
198+
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
199+
scat.add_grant(grant)
200+
201+
token = scat.to_jwt()
202+
assert_is_not_none(token)
203+
decoded_token = AccessToken.from_jwt(token, 'secret')
204+
self._validate_claims(decoded_token.payload)
205+
assert_equal(1, len(decoded_token.payload['grants']))
206+
assert_equal({
207+
'incoming': {
208+
'allow': True
209+
}
210+
}, decoded_token.payload['grants']['voice'])
211+
193212
def test_task_router_grant(self):
194213
grant = TaskRouterGrant(
195214
workspace_sid='WS123',

twilio/jwt/access_token/grants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ def to_payload(self):
9898
class VoiceGrant(AccessTokenGrant):
9999
"""Grant to access Twilio Programmable Voice"""
100100
def __init__(self,
101+
incoming_allow=None,
101102
outgoing_application_sid=None,
102103
outgoing_application_params=None,
103104
push_credential_sid=None,
104105
endpoint_id=None):
106+
self.incoming_allow = incoming_allow
107+
""" :type : bool """
105108
self.outgoing_application_sid = outgoing_application_sid
106109
""" :type : str """
107110
self.outgoing_application_params = outgoing_application_params
@@ -117,6 +120,10 @@ def key(self):
117120

118121
def to_payload(self):
119122
grant = {}
123+
if self.incoming_allow is True:
124+
grant['incoming'] = {}
125+
grant['incoming']['allow'] = True
126+
120127
if self.outgoing_application_sid:
121128
grant['outgoing'] = {}
122129
grant['outgoing']['application_sid'] = self.outgoing_application_sid

0 commit comments

Comments
 (0)