當前位置: 首頁>>代碼示例>>Python>>正文


Python jwt.get_unverified_claims方法代碼示例

本文整理匯總了Python中jose.jwt.get_unverified_claims方法的典型用法代碼示例。如果您正苦於以下問題:Python jwt.get_unverified_claims方法的具體用法?Python jwt.get_unverified_claims怎麽用?Python jwt.get_unverified_claims使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jose.jwt的用法示例。


在下文中一共展示了jwt.get_unverified_claims方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_token

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def check_token(self, renew=True):
        """
        Checks the exp attribute of the access_token and either refreshes
        the tokens by calling the renew_access_tokens method or does nothing
        :param renew: bool indicating whether to refresh on expiration
        :return: bool indicating whether access_token has expired
        """
        if not self.access_token:
            raise AttributeError('Access Token Required to Check Token')
        now = datetime.datetime.now()
        dec_access_token = jwt.get_unverified_claims(self.access_token)

        if now > datetime.datetime.fromtimestamp(dec_access_token['exp']):
            expired = True
            if renew:
                self.renew_access_token()
        else:
            expired = False
        return expired 
開發者ID:capless,項目名稱:warrant,代碼行數:21,代碼來源:__init__.py

示例2: verify_token

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def verify_token(self,token,id_name,token_use):
        kid = jwt.get_unverified_header(token).get('kid')
        unverified_claims = jwt.get_unverified_claims(token)
        token_use_verified = unverified_claims.get('token_use') == token_use
        if not token_use_verified:
            raise TokenVerificationException('Your {} token use could not be verified.')
        hmac_key = self.get_key(kid)
        try:
            verified = jwt.decode(token,hmac_key,algorithms=['RS256'],
                   audience=unverified_claims.get('aud'),
                   issuer=unverified_claims.get('iss'))
        except JWTError:
            raise TokenVerificationException('Your {} token could not be verified.')
        setattr(self,id_name,token)
        return verified 
開發者ID:capless,項目名稱:warrant,代碼行數:17,代碼來源:__init__.py

示例3: _decode_claims

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def _decode_claims(token):
        """Decode the claims in a token."""
        return jwt.get_unverified_claims(token) 
開發者ID:NabuCasa,項目名稱:hass-nabucasa,代碼行數:5,代碼來源:__init__.py

示例4: test_bad_claims

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def test_bad_claims(self):
        bad_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.iOJ5SiNfaNO_pa2J4Umtb3b3zmk5C18-mhTCVNsjnck'
        with pytest.raises(JWTError):
            jwt.get_unverified_claims(bad_token) 
開發者ID:mpdavis,項目名稱:python-jose,代碼行數:6,代碼來源:test_jwt.py

示例5: test_unverified_claims_string

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def test_unverified_claims_string(self):
        token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.aW52YWxpZCBjbGFpbQ.iOJ5SiNfaNO_pa2J4Umtb3b3zmk5C18-mhTCVNsjnck'
        with pytest.raises(JWTError):
            jwt.get_unverified_claims(token) 
開發者ID:mpdavis,項目名稱:python-jose,代碼行數:6,代碼來源:test_jwt.py

示例6: test_unverified_claims_list

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def test_unverified_claims_list(self):
        token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.WyJpbnZhbGlkIiwgImNsYWltcyJd.nZvw_Rt1FfUPb5OiVbrSYZGtWSE5c-gdJ6nQnTTBkYo'
        with pytest.raises(JWTError):
            jwt.get_unverified_claims(token) 
開發者ID:mpdavis,項目名稱:python-jose,代碼行數:6,代碼來源:test_jwt.py

示例7: test_unverified_claims_object

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def test_unverified_claims_object(self, claims, key):
        token = jwt.encode(claims, key)
        assert jwt.get_unverified_claims(token) == claims 
開發者ID:mpdavis,項目名稱:python-jose,代碼行數:5,代碼來源:test_jwt.py

示例8: requires_scope

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def requires_scope(self, required_scope):
        """Determines if the required scope is present in the Access Token
        Args:
            required_scope (str): The scope required to access the resource
        """
        token = self.get_token_auth_header()
        unverified_claims = jwt.get_unverified_claims(token)
        if unverified_claims.get("scope"):
            token_scopes = unverified_claims["scope"].split()
            for token_scope in token_scopes:
                if token_scope == required_scope:
                    return True
        return False 
開發者ID:mozilla-iam,項目名稱:sso-dashboard,代碼行數:15,代碼來源:idp.py

示例9: requires_scope

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def requires_scope(required_scope):
    """Determines if the required scope is present in the access token
    Args:
        required_scope (str): The scope required to access the resource
    """
    token = get_token_auth_header()
    unverified_claims = jwt.get_unverified_claims(token)
    if unverified_claims.get("scope"):
        token_scopes = unverified_claims["scope"].split()
        for token_scope in token_scopes:
            if token_scope == required_scope:
                return True
    return False 
開發者ID:auth0-samples,項目名稱:auth0-python-api-samples,代碼行數:15,代碼來源:server.py

示例10: lambda_handler

# 需要導入模塊: from jose import jwt [as 別名]
# 或者: from jose.jwt import get_unverified_claims [as 別名]
def lambda_handler(event, context):
    token = event['token']
    # get the kid from the headers prior to verification
    headers = jwt.get_unverified_headers(token)
    kid = headers['kid']
    # search for the kid in the downloaded public keys
    key_index = -1
    for i in range(len(keys)):
        if kid == keys[i]['kid']:
            key_index = i
            break
    if key_index == -1:
        print('Public key not found in jwks.json')
        return False
    # construct the public key
    public_key = jwk.construct(keys[key_index])
    # get the last two sections of the token,
    # message and signature (encoded in base64)
    message, encoded_signature = str(token).rsplit('.', 1)
    # decode the signature
    decoded_signature = base64url_decode(encoded_signature.encode('utf-8'))
    # verify the signature
    if not public_key.verify(message.encode("utf8"), decoded_signature):
        print('Signature verification failed')
        return False
    print('Signature successfully verified')
    # since we passed the verification, we can now safely
    # use the unverified claims
    claims = jwt.get_unverified_claims(token)
    # additionally we can verify the token expiration
    if time.time() > claims['exp']:
        print('Token is expired')
        return False
    # and the Audience  (use claims['client_id'] if verifying an access token)
    if claims['aud'] != app_client_id:
        print('Token was not issued for this audience')
        return False
    # now we can use the claims
    print(claims)
    return claims
        
# the following is useful to make this script executable in both
# AWS Lambda and any other local environments 
開發者ID:awslabs,項目名稱:aws-support-tools,代碼行數:45,代碼來源:decode-verify-jwt.py


注:本文中的jose.jwt.get_unverified_claims方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。