[Fiware-lab-help] Get access token using android library

Pedro Gonçalves pgoncalves at plux.info
Fri Jul 3 11:39:49 CEST 2015


Hi,

I'm using an android library to get the access token using explicit
authentication.

API: https://github.com/wuman/android-oauth-client

This API is build on top of google API:
https://github.com/google/google-oauth-java-client

The authorization token is being retrieved correctly. The problem is when I
try to exchange it for an access_token.

Here is my request using the API:

AuthorizationFlow flow = new AuthorizationFlow.Builder(
        //BearerToken.authorizationHeaderAccessMethod(),
        //BearerToken.queryParameterAccessMethod(),
        BearerToken.formEncodedBodyAccessMethod(),
        OAuth.HTTP_TRANSPORT,
        OAuth.JSON_FACTORY,
        new GenericUrl(LoginConstants.TOKEN_SERVER_URL),
        new BasicAuthentication(LoginConstants.CLIENT_ID,
                                LoginConstants.CLIENT_SECRET),
        LoginConstants.CLIENT_ID,
        LoginConstants.AUTHORIZATION_CODE_SERVER_URL)
        .setScopes(Lists.<String> newArrayList())
        .setCredentialStore(credentialStore)
        .build();

DocString:
/**

 * @param method method of presenting the access token to the resource
 *            server (for example
 *            {@link BearerToken#authorizationHeaderAccessMethod})
 * @param transport HTTP transport
 * @param jsonFactory JSON factory
 * @param tokenServerUrl token server URL
 * @param clientAuthentication client authentication or {@code null} for
 *            none (see
 *            {@link
TokenRequest#setClientAuthentication(HttpExecuteInterceptor)}
 *            )
 * @param clientId client identifier
 * @param authorizationServerEncodedUrl authorization server encoded URL
 */
public Builder(AccessMethod method,
        HttpTransport transport,
        JsonFactory jsonFactory,
        GenericUrl tokenServerUrl,
        HttpExecuteInterceptor clientAuthentication,
        String clientId,
        String authorizationServerEncodedUrl)

I've been able to Intercept the Request and Response, and this is the
result:

Request:

*Request getUrl: *https://account.lab.fiware.org/oauth2/token
*Request getRequestMethod:* POST
*Request getHeaders:* {accept=[application/json], accept-encoding=[gzip],
authorization=[Basic
MzNkYTk0NzFjZWQyNGFmMDk1ZDhiMDg0OWY1YTY0YmE6Yjc4M2Q5NmIwMzIxNGMxOWJmYjEyMzI5OGNjZDA2ZmM=]}
*Request getContent:*
code=QqU5dSHksT13hyb5yUMqZLGpge5S1f&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%2FCallback&scope
*Request getTransport:*
com.google.api.client.http.javanet.NetHttpTransport at 1182878e
*Request getResponseHeaders:* {content-type=[application/json], date=[Fri,
03 Jul 2015 09:27:16 GMT], connection=[close], content-language=[en],
server=[Apache/2.4.7 (Ubuntu)], transfer-encoding=[chunked],
vary=[Accept-Language,Cookie], x-android-received-millis=[1435915582841],
x-android-response-source=[NETWORK 400],
x-android-sent-millis=[1435915582737], x-frame-options=[SAMEORIGIN]}

Response:

*Response getStatusCode: *400
*Response getStatusMessage:* Bad Request
*Response getHeaders:* {content-type=[application/json], date=[Fri, 03 Jul
2015 09:27:16 GMT], connection=[close], content-language=[en],
server=[Apache/2.4.7 (Ubuntu)], transfer-encoding=[chunked],
vary=[Accept-Language,Cookie], x-android-received-millis=[1435915582841],
x-android-response-source=[NETWORK 400],
x-android-sent-millis=[1435915582737], x-frame-options=[SAMEORIGIN]}
*Response getMediaType:* application/json
*Response getTransport:*
com.google.api.client.http.javanet.NetHttpTransport at 1182878e
*Response getContentType*: application/json
*Response getContent:*
{
   "error" : ""
 }

IMPORTANT: I AM able to get the access token by using Chrome's REST client
with the
*SAME Request getContent* given above and the *SAME **Authorization: Basic
XXX* also given above, so they are correct.
I've tried to had Content-Type: application/x-www-form-urlencoded  to the
request, but the error resulting was the same.
I AM able to use this API with another Identity Management Servers, like
foursquare.

Having no information on the error response and sending exactly what you
define in:

https://github.com/ging/fi-ware-idm/wiki/Using-the-FIWARE-LAB-instance

It Becomes hard to solve it from my side. I've tried giving you every
information I have, but If you require more, please ask.


-- 

*[image: Inline image 1]*




*Pedro GonçalvesResearch Software EngineerPLUX - Wireless Biosignals, S.A.*
*Headquarters*

*Zona Industrial das Corredouras, Lt. 14 - 1º2630-369 Arruda dos
VinhosPortugalT: +351 263 978 572*
*Lisbon Office*
Av. 5 de Outubro, 70 - 8º
1050-059 Lisboa
Portugal
*T*: +351 211 956 542
*T*: +351 211 956 546
*F*: +351 211 956 531

*W*: www.plux.info
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fiware.org/private/fiware-lab-help/attachments/20150703/069c20aa/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 5208 bytes
Desc: not available
URL: <https://lists.fiware.org/private/fiware-lab-help/attachments/20150703/069c20aa/attachment.png>


More information about the Fiware-lab-help mailing list

You can get more information about our cookies and privacy policies clicking on the following links: Privacy policy   Cookies policy