[
https://issues.apache.org/jira/browse/OLTU-151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14184286#comment-14184286
]
Ankit Kumar commented on OLTU-151:
----------------------------------
This bug is invalid or had been fixed in the latest release.
While fetching an access token using GOOGLE as provider type and
AUTHORIZATION_CODE flow, OAuthJSONAccessTokenResponse class should be used to
map the response from server. Finally, I was able to use the following code to
successfully retrieve an access token from Google:
OAuthClientRequest request = OAuthClientRequest
.tokenProvider(OAuthProviderType.GOOGLE)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId("my_client_id")
.setClientSecret("my_client_secret")
.setRedirectURI("registered_redirect_uri").setCode(code)
.buildBodyMessage();
URLConnectionClient oAuthClient = new URLConnectionClient();
OAuthJSONAccessTokenResponse response = oAuthClient.execute(request, null,
HttpMethod.POST, OAuthJSONAccessTokenResponse.class);
System.out.println("Access token:" + response.getAccessToken());
No invalid_request error was received from google.
Hope this helps.
> URLClientConnection HTTP POST not encoded in entity body
> --------------------------------------------------------
>
> Key: OLTU-151
> URL: https://issues.apache.org/jira/browse/OLTU-151
> Project: Apache Oltu
> Issue Type: Bug
> Components: oauth2-client
> Affects Versions: oauth2-1.0.0
> Environment: Windows 7 x64, JDK1.8
> Reporter: Allan Cheong Tyng Huei
>
> Code:
> final String code = "this-is-an-authorization-code";
> OAuthClientRequest request =
> OAuthClientRequest.tokenProvider(OAuthProviderType.GOOGLE).setClientId(clientId).setClientSecret(secret).setRedirectURI("http://www.example.com/redirect").setCode(code).setGrantType(GrantType.AUTHORIZATION_CODE).buildQueryMessage();
> URLConnectionClient urlConnectionClient = new URLConnectionClient();
> OAuthResourceResponse response = urlConnectionClient.execute(request, null,
> HttpMethod.POST, OAuthResourceResponse.class);
> Response:
> {
> "error": "invalid_request",
> "error_description": "Required parameter is missing: grant_type"
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)