gpt4 book ai didi

php - "Invalid_grant"使用 Twinfield Openid Oauth 连接时的响应

转载 作者:行者123 更新时间:2023-12-04 16:00:02 24 4
gpt4 key购买 nike

这是我使用的库 https://github.com/php-twinfield/

当我调用 Oauth 登录时,这是一个问题。我已经完成了几乎带有用户名和密码的 API,但客户希望它带有 Oauth。我认为redirectUri 有问题。当我调用 Oauth 时,它总是显示:

{
"success": false,
"error": "invalid_grant"
}

这是我的凭据。 Clientid 和 clientsecret 是从邮件中获取的,并且重定向 uri 是从 Openid Twinfield 链接中设置的。如果凭证有任何错误,请纠正我。
clientId : Demorent
clientSecret : /iY7gyWn3Hkdgs4XzUG66SDyPNkk177x3A==
redirectUri : https://www.oauth.client.redirect.uri.com

使用的代码:
public function login(\Illuminate\Http\Request $request)
{
try {
// In the $request param all the credential given
$provider = new \PhpTwinfield\Secure\Provider\OAuthProvider([
'clientId' => $request->clientId,
'clientSecret' => $request->clientSecret,
'redirectUri' => $request->redirectUri
]);
// Here pass the authorization code
$accessToken = $provider->getAccessToken("authorization_code", ["code" =>'NLA000067']);
$refreshToken = $accessToken->getRefreshToken();
$office = \PhpTwinfield\Office::fromCode("1008");
$connection = new \PhpTwinfield\Secure\OpenIdConnectAuthentication($provider, $refreshToken, $office);
$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($connection);
$result = $customerApiConnector->get('1008',$office);
$jsonResponse = JsonResponse::success($result);

} catch(SoapFault $e) {
$jsonResponse = empty($e->getMessage()) ? JsonResponse::error(class_basename($e)) : JsonResponse::error($e->getMessage());
}
return $jsonResponse;
}

最佳答案

开始,invalid_grant是标准的 OAuth 2.0 错误参数。由于 OpenID Connect 是基于 OAuth 2.0 构建的,因此接收此响应是有效的。如果您查看 5.2 Error Response section ,你会发现下面的解释

invalid_grant


The provided authorization grant (e.g., authorizationcode, resource owner credentials) or refresh token isinvalid, expired, revoked, does not match the redirectionURI used in the authorization request, or was issued toanother client.


正如它所解释的,它可以是重定向 URI、资源所有者凭据中的任何内容。但是我发现您的代码存在与授权代码相关的问题。
    // Here pass the authorization code 
$accessToken = $provider->getAccessToken("authorization_code", ["code" =>'NLA000067']);
您是否使用硬编码 授权码 (NLA000067) ?这是错误的。授权码授权的第一步是获取授权码。然后只有您可以执行 token 请求。您从授权请求中获取授权代码,但我没有看到您正在这样做。
如果是这种情况,您得到的错误响应是完全有效的。如上所述 invalid_grant是由无效的授权码引起的。
p.s- 可能是 this链接将指导您纠正问题

关于php - "Invalid_grant"使用 Twinfield Openid Oauth 连接时的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50794466/

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