当前位置: 首页>>代码示例>>Python>>正文


Python jwt.decode函数代码示例

本文整理汇总了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
开发者ID:Adomako-Bismark,项目名称:twilio-python,代码行数:26,代码来源:test_task_router_capability.py

示例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'])
开发者ID:shuklv2,项目名称:NotyfyComplete,代码行数:7,代码来源:test_access_token.py

示例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'])
开发者ID:Adomako-Bismark,项目名称:twilio-python,代码行数:33,代码来源:test_task_router_taskqueue_capability.py

示例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'])
开发者ID:AgrAlert,项目名称:AgrAlert_Backend,代码行数:34,代码来源:test_capability.py

示例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
开发者ID:nadyac,项目名称:answer-SMS,代码行数:28,代码来源:test_task_router_capability.py

示例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"])
开发者ID:mattmac4241,项目名称:twilioTest,代码行数:8,代码来源:test_access_token.py

示例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"])
开发者ID:nadyac,项目名称:answer-SMS,代码行数:8,代码来源:test_task_router_worker_capability.py

示例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)
开发者ID:nadyac,项目名称:answer-SMS,代码行数:9,代码来源:test_task_router_worker_capability.py

示例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'])
开发者ID:Adomako-Bismark,项目名称:twilio-python,代码行数:9,代码来源:test_access_token.py

示例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'])
开发者ID:shuklv2,项目名称:NotyfyComplete,代码行数:10,代码来源:test_access_token.py

示例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"])
开发者ID:mattmac4241,项目名称:twilioTest,代码行数:10,代码来源:test_access_token.py

示例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"])
开发者ID:mattmac4241,项目名称:twilioTest,代码行数:10,代码来源:test_access_token.py

示例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"])
开发者ID:nadyac,项目名称:answer-SMS,代码行数:10,代码来源:test_task_router_worker_capability.py

示例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])
开发者ID:adamchainz,项目名称:twilio-python,代码行数:10,代码来源:test_capability.py

示例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'])
开发者ID:Adomako-Bismark,项目名称:twilio-python,代码行数:10,代码来源:test_access_token.py


注:本文中的twilio.jwt.decode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。