本文整理汇总了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
示例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
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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
示例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