gpt4 book ai didi

PayPal id_token 验证

转载 作者:太空宇宙 更新时间:2023-11-03 15:48:06 25 4
gpt4 key购买 nike

我正在实现“使用 PayPal 登录”功能。应该相当简单,但不幸的是 PayPal 缺少文档(只描述了一些基本的东西)。

我使用“使用 PayPal 登录”小部件获取 authorization_code。比我向https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice提出请求并使用 access_token、refresh_token 和 id_token 获取 JSON。我想获得唯一的用户标识符,所以我解码了 id_token,但我无法验证我的 id_token 的签名。 Id_token header 包含 {"alg": "HS256", "typ": "JWT"}

我应该使用什么 secret ?尝试了我的应用程序的 secret (与我用来访问 token 服务的 secret 相同),但它没有用(使用 https://jwt.io/ 调试器)。

最佳答案

PayPal 不兼容 OpenID 连接。 This答案说明了原因。

PayPal 公开配置端点 - https://www.paypalobjects.com/.well-known/openid-configuration .它只支持HS256,不支持或提及RS256。这可能是由于 ID token 的专有验证。例如,用作不记名 token 的 ID token 。

替代解决方案是调用 userinfo 端点,如 document 所述.可以使用 access token 调用此端点,文档说它将返回 user_id

user_id - identifier for the end-user at the issuer.

虽然在userinfo中找到的user_id似乎与从id_token中提取的sub不同。

如果签名算法是RS256如何找到公钥

ID token 是 JWT。正如您所发现的,它包含一个充当 MAC 的 JWS 签名。

此签名是使用私钥签名的。 id token 的接收者可以使用公钥验证 token 。要查找公钥,openid conenct 指定一个发现文件。您可以从 specification 阅读更多相关信息

在发现文档中,您会得到一个特殊端点来推断配置 .well-known/openid-configuration。并且必须具有配置响应的元数据之一是 jwk_url

jwks_uri

REQUIRED. URL of the OP's JSON Web Key Set [JWK] document. This contains the signing key(s) the RP uses to validate signatures from the OP. The JWK Set MAY also contain the Server's encryption key(s), which are used by RPs to encrypt requests to the Server. When both signing and encryption keys are made available, a use (Key Use) parameter value is REQUIRED for all keys in the referenced JWK Set to indicate each key's intended usage. Although some algorithms allow the same key to be used for both signatures and encryption, doing so is NOT RECOMMENDED, as it is less secure. The JWK x5c parameter MAY be used to provide X.509 representations of keys provided. When used, the bare key values MUST still be present and MUST match those in the certificate.

关于PayPal id_token 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45449405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com