本文整理汇总了Python中twilio.jwt.decode函数的典型用法代码示例。如果您正苦于以下问题:Python decode函数的具体用法?Python decode怎么用?Python decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_task_queue_default
def test_task_queue_default(self):
account_sid = "AC123"
auth_token = "foobar"
workspace_sid = "WS456"
taskqueue_sid = "WQ789"
capability = TaskRouterCapability(account_sid, auth_token, workspace_sid, taskqueue_sid)
capability.generate_token()
token = capability.generate_token()
self.assertNotEqual(None, token)
decoded = jwt.decode(token, auth_token)
self.assertNotEqual(None, decoded)
self.check_decoded(decoded, account_sid, workspace_sid, taskqueue_sid, taskqueue_sid)
policies = decoded['policies']
self.assertEqual(len(policies), 3)
for method, url, policy in [
('GET', "https://event-bridge.twilio.com/v1/wschannels/AC123/WQ789", policies[0]),
('POST', "https://event-bridge.twilio.com/v1/wschannels/AC123/WQ789", policies[1])
('GET', "https://taskrouter.twilio.com/v1/Workspaces/WS456/TaskQueues/WQ789", policies[2])
]:
yield self.check_policy, method, url, policy
示例2: test_empty_grants
def test_empty_grants(self):
scat = AccessToken(SIGNING_KEY_SID, ACCOUNT_SID, 'secret')
token = str(scat)
assert_is_not_none(token)
payload = decode(token, 'secret')
self._validate_claims(payload)
assert_equal([], payload['grants'])
示例3: test_default
def test_default(self):
token = self.capability.generate_token()
self.assertNotEqual(None, token)
decoded = jwt.decode(token, self.auth_token)
self.assertNotEqual(None, decoded)
policies = decoded['policies']
self.assertEqual(len(policies), 3)
# websocket GET
get_policy = policies[0]
self.assertEqual("https://event-bridge.twilio.com/v1/wschannels/AC123/WQ789", get_policy['url'])
self.assertEqual("GET", get_policy['method'])
self.assertTrue(get_policy['allow'])
self.assertEqual({}, get_policy['query_filter'])
self.assertEqual({}, get_policy['post_filter'])
# websocket POST
post_policy = policies[1]
self.assertEqual("https://event-bridge.twilio.com/v1/wschannels/AC123/WQ789", post_policy['url'])
self.assertEqual("POST", post_policy['method'])
self.assertTrue(post_policy['allow'])
self.assertEqual({}, post_policy['query_filter'])
self.assertEqual({}, post_policy['post_filter'])
# fetch GET
fetch_policy = policies[2]
self.assertEqual("https://taskrouter.twilio.com/v1/Workspaces/WS456/TaskQueues/WQ789", fetch_policy['url'])
self.assertEqual("GET", fetch_policy['method'])
self.assertTrue(fetch_policy['allow'])
self.assertEqual({}, fetch_policy['query_filter'])
self.assertEqual({}, fetch_policy['post_filter'])
示例4: test_defaults
def test_defaults(self):
token = self.cap.generate_token()
decoded = jwt.decode(token, self.auth_token)
self.assertTrue(decoded is not None)
websocket_url = (
'https://event-bridge.twilio.com/v1/wschannels/%s/%s' %
(self.account_sid, self.worker_sid)
)
expected = [
{
'url': websocket_url,
'method': 'GET',
'allow': True,
'query_filter': {},
'post_filter': {},
},
{
'url': websocket_url,
'method': 'POST',
'allow': True,
'query_filter': {},
'post_filter': {},
},
{
'url':
'https://taskrouter.twilio.com/v1/Workspaces/WS456/Activities',
'method': 'GET',
'allow': True,
'query_filter': {},
'post_filter': {},
},
]
self.assertEqual(expected, decoded['policies'])
示例5: test_worker_default
def test_worker_default(self):
account_sid = "AC123"
auth_token = "foobar"
workspace_sid = "WS456"
worker_sid = "WK789"
capability = TaskRouterCapability(account_sid, auth_token, workspace_sid, worker_sid)
capability.generate_token()
token = capability.generate_token()
self.assertIsNotNone(token)
decoded = jwt.decode(token, auth_token)
self.assertIsNotNone(decoded)
self.check_decoded(decoded, account_sid, workspace_sid, worker_sid, worker_sid)
policies = decoded["policies"]
self.assertEqual(len(policies), 5)
for method, url, policy in [
("GET", "https://taskrouter.twilio.com/v1/Workspaces/WS456/Activities", policies[0]),
("GET", "https://taskrouter.twilio.com/v1/Workspaces/WS456/Tasks/**", policies[1]),
("GET", "https://taskrouter.twilio.com/v1/wschannels/AC123/WK789", policies[2]),
("POST", "https://event-bridge.twilio.com/v1/wschannels/AC123/WK789", policies[3]),
("GET", "https://taskrouter.twilio.com/v1/Workspaces/WS456/Workers/WK789", policies[4]),
]:
yield self.check_policy, method, url, policy
示例6: test_empty_grants
def test_empty_grants(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, "secret")
token = str(scat)
assert_is_not_none(token)
payload = decode(token, "secret")
self._validate_claims(payload)
assert_equal({}, payload["grants"])
示例7: test_generate_token_with_default_ttl
def test_generate_token_with_default_ttl(self):
token = self.capability.generate_token()
self.assertIsNotNone(token)
decoded = jwt.decode(token, self.auth_token)
self.assertIsNotNone(decoded)
self.assertEqual(int(time.time()) + 3600, decoded["exp"])
示例8: test_generate_token
def test_generate_token(self):
token = self.capability.generate_token()
self.assertIsNotNone(token)
decoded = jwt.decode(token, self.auth_token)
self.assertIsNotNone(decoded)
self.check_decoded(decoded, self.account_sid, self.workspace_sid, self.worker_sid, self.worker_sid)
示例9: test_nbf
def test_nbf(self):
now = int(time.mktime(datetime.now().timetuple()))
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', nbf=now)
token = str(scat)
assert_is_not_none(token)
payload = decode(token, 'secret')
self._validate_claims(payload)
assert_equal(now, payload['nbf'])
示例10: test_single_grant
def test_single_grant(self):
scat = AccessToken(SIGNING_KEY_SID, ACCOUNT_SID, 'secret')
scat.add_grant('https://api.twilio.com/**')
token = str(scat)
assert_is_not_none(token)
payload = decode(token, 'secret')
self._validate_claims(payload)
assert_equal(1, len(payload['grants']))
assert_equal('https://api.twilio.com/**', payload['grants'][0]['res'])
assert_equal(['*'], payload['grants'][0]['act'])
示例11: test_ip_messaging_grant
def test_ip_messaging_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, "secret")
scat.add_grant(IpMessagingGrant())
token = str(scat)
assert_is_not_none(token)
payload = decode(token, "secret")
self._validate_claims(payload)
assert_equal(1, len(payload["grants"]))
assert_equal({}, payload["grants"]["ip_messaging"])
示例12: test_conversations_grant
def test_conversations_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, "secret")
scat.add_grant(ConversationsGrant())
token = str(scat)
assert_is_not_none(token)
payload = decode(token, "secret")
self._validate_claims(payload)
assert_equal(1, len(payload["grants"]))
assert_equal({}, payload["grants"]["rtc"])
示例13: test_generate_token_with_custom_ttl
def test_generate_token_with_custom_ttl(self):
ttl = 10000
token = self.capability.generate_token(ttl)
self.assertIsNotNone(token)
decoded = jwt.decode(token, self.auth_token)
self.assertIsNotNone(decoded)
self.assertEqual(int(time.time()) + 10000, decoded["exp"])
示例14: test_allow_task_reservation_updates
def test_allow_task_reservation_updates(self):
self.cap.allow_task_reservation_updates()
token = self.cap.generate_token()
decoded = jwt.decode(token, self.auth_token)
self.assertTrue(decoded is not None)
url = "https://taskrouter.twilio.com/v1/Workspaces/{0}/Tasks/**".format(self.workspace_sid)
expected = {"url": url, "method": "POST", "allow": True, "query_filter": {}, "post_filter": {}}
self.assertEqual(expected, decoded["policies"][-1])
示例15: test_identity
def test_identity(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', identity='[email protected]')
token = str(scat)
assert_is_not_none(token)
payload = decode(token, 'secret')
self._validate_claims(payload)
assert_equal({
'identity': '[email protected]'
}, payload['grants'])