猿问

从断言中解码 JWT - Google 登录

我正在尝试在 Actions on Google 中实现帐户链接(使用此)


我被困在其中的处理自动链接步骤。assertion当我尝试使用此处指定的python-jose库对其进行解码时,我收到了请求!


from jose import jwt

key = "728f4016652079b9ed99861bb09bafc5a45baa86" # PUBLIC KEY OF GOOGLE from https://www.googleapis.com/oauth2/v3/certs

encoded = "ENCODED_ASSERTION"

decoded = jwt.decode(encoded, key, algorithms='RS256')

print (decoded)

当我运行此代码时,它显示


Traceback (most recent call last):


File "/Users/jay.patel/env372/lib/python3.7/site-packages/jose/backends/pycrypto_backend.py", line 72, in __init__

    self.prepared_key = RSA.importKey(key)

  File "/Users/jay.patel/env372/lib/python3.7/site-packages/Crypto/PublicKey/RSA.py", line 757, in import_key

    raise ValueError("RSA key format is not supported")

ValueError: RSA key format is not supported


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/Users/jay.patel/PycharmProjects/Prac/jwt.py", line 19, in <module>

    decoded = jwt.decode(encoded, key, algorithms='RS256')

  File "/Users/jay.patel/env372/lib/python3.7/site-packages/jose/jwt.py", line 135, in decode

    payload = jws.verify(token, key, algorithms, verify=verify_signature)

  File "/Users/jay.patel/env372/lib/python3.7/site-packages/jose/jws.py", line 77, in verify

    _verify_signature(signing_input, header, signature, key, algorithms)

  File "/Users/jay.patel/env372/lib/python3.7/site-packages/jose/jws.py", line 264, in _verify_signature

    if not _sig_matches_keys(keys, signing_input, signature, alg):


我究竟做错了什么??我刚刚使用了 RS256,因为它是在 Google 的公钥中指定的(以JWK或PEM格式提供)


PS 当我尝试使用算法解码此处的断言时,RS256它显示无效签名错误,如下图所示。

鸿蒙传说
浏览 334回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答