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


Python JWT.unpack方法代码示例

本文整理汇总了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
开发者ID:TransparentHealth,项目名称:python-poetri,代码行数:41,代码来源:verify_jws_with_jwk_url.py

示例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
开发者ID:biancini,项目名称:ojou_course,代码行数:32,代码来源:jwt_sign.py

示例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)
开发者ID:biancini,项目名称:ojou_course,代码行数:32,代码来源:JWS.py


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