clientId = xxxxxx
clientSecret = xxxxxxxx
applicationHost = xxxxxxxxx
我的授权码请求:
OAuthClientRequest oAuthClientRequest = OAuthClientRequest
.authorizationProvider(OAuthProviderType.GOOGLE)
.setResponseType("code")
.setClientId(clientId)
.setParameter("access_type", "online")
.setRedirectURI(applicationHost + "auth/google/callback")
.setScope("https://www.googleapis.com/auth/plus.login")
.buildQueryMessage();
response.sendRedirect(oAuthClientRequest.getLocationUri());
我正在获取授权码。但每当我使用此代码发送access_token请求时,我都会收到错误消息。 (守则400)
我的access_token请求:
OAuthClientRequest oAuthClientRequest = OAuthClientRequest
.tokenProvider(OAuthProviderType.GOOGLE)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(clientId)
.setClientSecret(clientSecret)
.setParameter("access_type", "online")
.setRedirectURI(applicationHost + "auth/google/callback")
.setCode(code)
.buildQueryMessage();
GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(
oAuthClientRequest, GitHubTokenResponse.class);
return oAuthResponse.getAccessToken();
OAuth2游乐场回复:
HTTP/1.1 400 Bad Request
Alternate-protocol: 443:quic
Content-length: 37
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
X-google-cache-control: remote-fetch
-content-encoding: gzip
Server: GSE
Via: HTTP/1.1 GWA
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Mon, 17 Feb 2014 09:03:52 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json
Expires: Fri, 01 Jan 1990 00:00:00 GMT
{
"error": "unauthorized_client"
}
请帮帮我。提前谢谢。
答案 0 :(得分:2)
您正在从您的应用程序(即客户端ID XXXXX)中获取一个身份验证代码并将其粘贴到另一个应用程序(客户端ID为YYYYY的oauth游乐场)并期望它能够正常工作?
那不行。
如果您进入Gear选项并输入应用程序的凭据,它可能会有效。但我有点困惑为什么你这样做。你试图解决的问题是什么?
这个答案可能有助于How do I authorise an app (web or installed) without user intervention? (canonical ?)