"Invalid_grant";使用Twinfield Openid Oauth连接时的响应 [英] "Invalid_grant" response when use Twinfield Openid Oauth connect

查看:150
本文介绍了"Invalid_grant";使用Twinfield Openid Oauth连接时的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

当我调用Oauth登录时,这是一个问题.我已经用用户名和密码完成了几乎所有的API,但是客户端希望使用Oauth来完成.我认为redirectUri中存在问题.当我打电话给Oauth时,它总是显示:

It's an issue when I call the Oauth login. I have completed almost APIs with username and password but client wants it with Oauth. I think there is a problem in redirectUri. When I called Oauth it always show:

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

这是我的凭证.从邮件中获取Clientid和clientsecret,并从Openid Twinfield链接中设置重定向uri.如果证书有任何错误,请纠正我.

This is my credential. Clientid and clientsecret is obtained from mail and the redirect uri set from Openid Twinfield link. Please correct me if there is anything wrong in credential.

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;
}

推荐答案

@AnandPandey,请按照以下步骤操作

@AnandPandey, follow the steps below

步骤1:

您首先需要构建要调用的URL,才能连接到Twinfield.为此,您应该具有如下所示的网址.

You first need to build the url that you would invoke, to connect to Twinfield. And for doing that you should have the url as shown below.

https://login.twinfield.com/auth/authentication/connect/authorize?
client_id=Demorent
&client_secret=/iY7gyWn3Hkdgs4XzUG66SDyPNkk177x3A==
&redirect_uri=https://www.oauth.client.redirect.uri.com
&response_type=code
&force_login=0
&scope=openid+twf.user+twf.organisation+twf.organisationUser+offline_access
&state=STATELESS
&nonce=nonce

注意:

1) redirect_uri 必须与您在Twinfield中注册的完全相同.

1) The redirect_uri needs to be exactly the same as that you have registered with Twinfield.

2)应该显示如上所示的 scope 参数,并且其值应与上面给出的值相同

2) the scope parameter as shown above should be present and with the same value as it is given above

3)验证您的client_id& client_secret

3) verify your client_id & client_secret

如果一切顺利,将显示Twinflield登录页面,您需要在其中使用您的凭据登录.成功登录后,您将被重定向到权限授予页面,以基本上授予对您的应用程序的访问权限以访问Twinfield数据. 单击许可"后,您将被重定向回使用授权码指定的端点.

If all goes fine, you will be shown the Twinflield login page where in you need to login with your credentials. After successfull login you would be redirected to permission grants page to basically grant access to your application to access Twinfield data. Once you click on "Permit" you would be redirected back to the endpoint that you have specified with the authorization code.

步骤2:

下一步是调用Twinfield accessTokenUri https://login.twinfield.com/auth/authentication/connect/token 带有以下标题

The next step is to invoke Twinfield accessTokenUri https://login.twinfield.com/auth/authentication/connect/token with the following headers

header.add("code",authorizationCodeFromStep1);
header.add("redirect_uri", yourRegisteredRedirectUri);
header.add("grant_type", "authorization_code");
header.add("client_id", "Demorent");
header.add("client_secret", "/iY7gyWn3Hkdgs4XzUG66SDyPNkk177x3A==");

如果上述所有传递的参数正确,您将获得id_token,accessToken,refreshToken,token_type和expires_in的响应

If all the above parameters passed is correct, you would get a response back with id_token, accessToken, refreshToken, token_type and expires_in

这篇关于"Invalid_grant";使用Twinfield Openid Oauth连接时的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆