title: android application connecting to 'sparklr' J2EE application using OAuth2
body: <p>I'm trying to make an OAuth 2.0 Provider and an Android application that is able to connect to the provider using OAuth 2.0. I have the following setup:</p>
  
  <p>A tomcat server with the J2EE example OAuth 2.0 provider named 'sparklr' from springsource. When I test it with the example 'Tonr' it works perfectly.
  Now I want an Android application that does more or less the same as the example Tonr application. Accessing the photo resources from the sparklr application using OAuth 2.0</p>
  
  <p>But I'm stuck. I'm using the leeloo libraries which have been moved to apache amber. To be exact I'm using the following tutorial: <a href="http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/" rel="nofollow">http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/</a></p>
  
  <p>The first fase of the application works. The browser starts and I get the sparklr page to login and authorize the request.
  But when I try to get the access token the application crashes. I didn't get any wiser from the logcat so I used debug to get the request. The following code builds the request:</p>
  
  <pre><code>request = OAuthClientRequest.tokenLocation("http://10.106.0.16:8084/sparklr/oauth/token")
                  .setGrantType(GrantType.AUTHORIZATION_CODE)
                 .setClientId("tonr")
                  .setClientSecret("secret")
                  .setRedirectURI("MyOAuth2POC://oauthresponse")
                  .setCode(code)
                  .setScope("trust")
                              .buildBodyMessage();
  </code></pre>
  
  <p>And I get my url: <a href="http://10.106.0.16:8084/sparklr/oauth/token?scope=read&amp;code=iCMZPE&amp;client_secret=secret&amp;client_id=tonr&amp;grant_type=authorization_code&amp;redirect_uri=MyOAuth2POC%3A%2F%2Foauthresponse" rel="nofollow">http://10.106.0.16:8084/sparklr/oauth/token?scope=read&amp;code=iCMZPE&amp;client_secret=secret&amp;client_id=tonr&amp;grant_type=authorization_code&amp;redirect_uri=MyOAuth2POC%3A%2F%2Foauthresponse</a></p>
  
  <p>All the parameters are there and it looks correct to me.  But I get the following output:</p>
  
  <blockquote>
    <p>{   "error": "invalid_grant",   "error_description": "Invalid
    authorization code: MASCID" }</p>
  </blockquote>
  
  <p>So obviously something goes wrong with the scope parameter. I tried to set it to 'trust' instead of 'read' but no different result. Do I need to change something in the sparklr application? Or am I doing something wrong with the Android application, and what?</p>
  
  <p>Hope someone can help.</p>
  
  <p>thx!</p>