当前位置: 首页 > 工具软件 > authlib > 使用案例 >

token要加编码decode吗_Authlib jwt token decode在函数内部不工作

龙安阳
2023-12-01

我使用authlib库来解码JWT令牌。在

当我按原样运行时,这个代码运行得很好。在from authlib.specs.rfc7519 import jwt

encoded_jwt = '''eyJ0eXAiOiJKV1Qi.....'''

secret = b'''-----BEGIN PUBLIC KEY-----

.....

-----END PUBLIC KEY-----'''

claims = jwt.decode(encoded_jwt, secret)

print(type(claims))

import json

json_parse = json.loads(json.dumps(claims))

email = json_parse['http://wso2.org/claims/emailaddress']

print(email)

roles = json_parse['http://wso2.org/claims/role']

print(roles)

email, roles[-1]

但是当我把这个加到函数里,它就不起作用了。通过这个问题,我不能在烧瓶框架中使用它。下面的代码不工作。请不要回答检查公钥,因为它在上面的代码中工作正常。在

^{pr2}$

我得到的错误是:Traceback (most recent call last): File

"/home/sathiyakugan/PycharmProjects/JWTsample/ss.py", line 50, in

email,role=getsessions() File "/home/sathiyakugan/PycharmProjects/JWTsample/ss.py", line 39, in

getsessions

claims = jwt.decode(encoded_jwt, secret) File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/authlib/specs/rfc7519/jwt.py",

line 119, in decode

data = self._jws.deserialize_compact(s, key_func, decode_payload) File

"/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/authlib/specs/rfc7515/jws.py",

line 108, in deserialize_compact

self._algorithms, jws_header, payload, key) File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/authlib/specs/rfc7515/util.py",

line 14, in prepare_algorithm_key

key = algorithm.prepare_public_key(key) File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/authlib/specs/rfc7518/_backends/_key_cryptography.py",

line 28, in prepare_public_key

return load_pem_public_key(key, backend=default_backend()) File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/cryptography/hazmat/primitives/serialization.py",

line 24, in load_pem_public_key

return backend.load_pem_public_key(data) File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/backend.py",

line 1040, in load_pem_public_key

self._handle_key_loading_error() File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/backend.py",

line 1291, in _handle_key_loading_error

raise ValueError("Could not deserialize key data.") ValueError: Could not deserialize key data.

请帮助我哪里出了问题。我已经为这个问题挣扎了两天。请帮忙。在

 类似资料: