title: Spring - oauth2 - exchange authorization code for refresh and access tokens
body: <p>I want to exchange authorization code for refresh and access tokens with Spring oauth2 client package. My code looks like:</p>
  
  <pre><code>public static void main(String[] args) {
  
    AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
    resource.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resource.setAccessTokenUri("http://localhost:8080/oauth/token");
    resource.setClientId("my-client-with-secret");
    resource.setClientSecret("secret");
  
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("o9subu");
  
    AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider();
    OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, request);
  
    System.out.println(accessToken.getValue());
  }
  </code></pre>
  
  <p>The provider is from <a href="https://github.com/spring-projects/spring-security-oauth/tree/master/tests/annotation/approval" rel="nofollow noreferrer">https://github.com/spring-projects/spring-security-oauth/tree/master/tests/annotation/approval</a> and I've taken the temp oauth2 code from the browser when I called the provider directly.</p>
  
  <p>And the error message is</p>
  
  <blockquote>
    <p>Exception in thread "main" error="invalid_request", error_description="Possible CSRF detected - state parameter was required but no state could be found"
        at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.getParametersForTokenRequest(AuthorizationCodeAccessTokenProvider.java:255)
        at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.obtainAccessToken(AuthorizationCodeAccessTokenProvider.java:209)</p>
  </blockquote>
  
  <p>I still want to request for access_token and secret_token by myself because I obtain the oauth2 code from another system.</p>