本文整理汇总了Python中jwkest.jwt.JWT.unpack方法的典型用法代码示例。如果您正苦于以下问题:Python JWT.unpack方法的具体用法?Python JWT.unpack怎么用?Python JWT.unpack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jwkest.jwt.JWT
的用法示例。
在下文中一共展示了JWT.unpack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verify_poet_via_url
# 需要导入模块: from jwkest.jwt import JWT [as 别名]
# 或者: from jwkest.jwt.JWT import unpack [as 别名]
def verify_poet_via_url(my_jws):
# load the Signed JWT (JWS)
my_jws = my_jws.rstrip().lstrip()
signed_token = JWS(my_jws)
# create aplain old JWT so we can fish out the 'iss'
t = JWT()
unpacked = t.unpack(token=my_jws)
payload = unpacked.payload()
if "iss" not in payload:
print("Missing 'iss' claim in the JWS payload.")
exit(1)
else:
iss = payload['iss']
# Fetch the public key from iss
url = "https://%s/.well-known/poet.jwk" % (iss)
r = requests.get(url)
if r.status_code != 200:
print("The key could not be fetched.")
exit(1)
# load the JWK into an RSA Key structure
rsak = RSAKey(**r.json())
try:
vt = signed_token.verify_compact(signed_token.msg, keys=[rsak])
retval = vt
except BadSignature:
retval = {"error": "The signature did not match"}
except NoSuitableSigningKeys:
retval = {"error": str(sys.exc_info()[1])}
except DeSerializationNotPossible:
retval = {"error": str(sys.exc_info()[1])}
except:
retval = {"error": str(sys.exc_info())}
return retval
示例2: key
# 需要导入模块: from jwkest.jwt import JWT [as 别名]
# 或者: from jwkest.jwt.JWT import unpack [as 别名]
# $ ssh-keygen -t rsa -b 4096
# and provide the foo filename with requested.
#
# Now a JWS can be created as follow:
# - retrieve the rsa key (the example below will also print it in the JWK section)
# - use the JWS object to create the token specifying the algorithm to be used for signing
# - call the method sign_compact providing an array of keys (eventually containing 1 key only) to be used for signing
# - the example belows shows the content of the JWT, by printing it
# - the signature can be verified with the method verify_compact (of course providing the same keys used for signing)
payload = {"iss": "jow",
"exp": 1300819380,
"http://example.com/is_root": True}
keys = [RSAKey(key=import_rsa_key_from_file("foo"))]
jws = JWS(payload, alg="RS512").sign_compact(keys)
print "jwt signed:", jws
print
########################################
jwt_received = JWT()
jwt_received.unpack(jws)
print "jwt headers:", jwt_received.headers
print "jwt part 1:", jwt_received.part[1]
print
_rj = JWS()
info = _rj.verify_compact(jws, keys)
print "Verified info:", info
示例3: JWS
# 需要导入模块: from jwkest.jwt import JWT [as 别名]
# 或者: from jwkest.jwt.JWT import unpack [as 别名]
# The JWS class can not work directly with rsa keys.
# In this case the rsa key is wrapped in a RSAKey
keys = [RSAKey(key=import_rsa_key_from_file("foo"))]
_jws = JWS(payload, alg="RS512")
_jwt = _jws.sign_compact(keys)
print("Signed jwt:", _jwt)
print()
# The JWT class can be used to peek into a JWT, whether is is signed or
# encrypted. It will not do any verificiation or decryption just unpacking
# the JWT.
jwt = JWT()
jwt.unpack(_jwt)
print("jwt headers:", jwt.headers)
# Part 0 is the headers
# Part 1 is the payload message
print("jwt part 1:", jwt.part[1])
print()
# If you want to verify the signature you have to use the JWS class
_rj = JWS()
# If everything is OK the verify_compact method will return the payload message
info = _rj.verify_compact(_jwt, keys)
print("Verified info:", info)