コード例 #1
0
ファイル: access_token.py プロジェクト: pkim90/udacity
    def to_jwt(self, algorithm='HS256'):
        now = int(time.time())
        headers = {"typ": "JWT", "cty": "twilio-fpa;v=1"}

        grants = {}
        if self.identity:
            grants["identity"] = self.identity

        for grant in self.grants:
            grants[grant.key] = grant.to_payload()

        payload = {
            "jti": '{0}-{1}'.format(self.signing_key_sid, now),
            "iss": self.signing_key_sid,
            "sub": self.account_sid,
            "exp": now + self.ttl,
            "grants": grants
        }

        if self.nbf is not None:
            payload['nbf'] = self.nbf

        return jwt.encode(payload,
                          self.secret,
                          headers=headers,
                          algorithm=algorithm)
コード例 #2
0
    def to_jwt(self, algorithm='HS256'):
        now = int(time.time())
        headers = {
            "typ": "JWT",
            "cty": "twilio-fpa;v=1"
        }

        grants = {}
        if self.identity:
            grants["identity"] = self.identity

        for grant in self.grants:
            grants[grant.key] = grant.to_payload()

        payload = {
            "jti": '{0}-{1}'.format(self.signing_key_sid, now),
            "iss": self.signing_key_sid,
            "sub": self.account_sid,
            "exp": now + self.ttl,
            "grants": grants
        }

        if self.nbf is not None:
            payload['nbf'] = self.nbf

        return jwt.encode(payload, self.secret, headers=headers,
                          algorithm=algorithm)
コード例 #3
0
ファイル: util.py プロジェクト: NYUITP/sp13_twl
    def generate(self, expires=3600):
        """Generate a valid JWT token with an expiration date.

        :param int expires: The token lifetime, in seconds. Defaults to
                            1 hour (3600)

        """
        payload = self.payload()
        payload['iss'] = self.account_sid
        payload['exp'] = int(time.time() + expires)
        return jwt.encode(payload, self.auth_token)
コード例 #4
0
ファイル: util.py プロジェクト: pftp/sample-projects
    def generate(self, expires=3600):
        """Generate a valid JWT token with an expiration date.

        :param int expires: The token lifetime, in seconds. Defaults to
                            1 hour (3600)

        """
        payload = self.payload()
        payload['iss'] = self.account_sid
        payload['exp'] = int(time.time() + expires)
        return jwt.encode(payload, self.auth_token)
コード例 #5
0
    def _generate_token(self, ttl, attributes=None):
        payload = {
            'iss': self.account_sid,
            'exp': int(time.time()) + ttl,
            'version': TASK_ROUTER_VERSION,
            'friendly_name': self.channel_id,
            'policies': self.policies,
        }

        if attributes is not None:
            payload.update(attributes)

        return jwt.encode(payload, self.auth_token, 'HS256')
コード例 #6
0
 def test_bad_secret(self):
     right_secret = 'foo'
     bad_secret = 'bar'
     jwt_message = jwt.encode(self.payload, right_secret)
     self.assertRaises(jwt.DecodeError, jwt.decode, jwt_message, bad_secret)
コード例 #7
0
 def test_encode_decode(self):
     secret = 'secret'
     jwt_message = jwt.encode(self.payload, secret)
     decoded_payload = jwt.decode(jwt_message, secret)
     self.assertEqual(decoded_payload, self.payload)
コード例 #8
0
 def test_allow_skip_verification(self):
     right_secret = 'foo'
     jwt_message = jwt.encode(self.payload, right_secret)
     decoded_payload = jwt.decode(jwt_message, verify=False)
     self.assertEqual(decoded_payload, self.payload)
コード例 #9
0
ファイル: test_jwt.py プロジェクト: 42cc/twilio-python
 def test_bad_secret(self):
     right_secret = 'foo'
     bad_secret = 'bar'
     jwt_message = jwt.encode(self.payload, right_secret)
     self.assertRaises(jwt.DecodeError, jwt.decode, jwt_message, bad_secret)
コード例 #10
0
ファイル: test_jwt.py プロジェクト: 42cc/twilio-python
 def test_encode_decode(self):
     secret = 'secret'
     jwt_message = jwt.encode(self.payload, secret)
     decoded_payload = jwt.decode(jwt_message, secret)
     self.assertEqual(decoded_payload, self.payload)
コード例 #11
0
ファイル: test_jwt.py プロジェクト: 42cc/twilio-python
 def test_allow_skip_verification(self):
     right_secret = 'foo'
     jwt_message = jwt.encode(self.payload, right_secret)
     decoded_payload = jwt.decode(jwt_message, verify=False)
     self.assertEqual(decoded_payload, self.payload)