title: How do you set a resource ID for a token?
body: <p>I try to implement a RESTFul webservice with OAuth using this guide: <a href="https://spring.io/guides/tutorials/bookmarks" rel="noreferrer">https://spring.io/guides/tutorials/bookmarks</a></p>
  
  <p>I can successfully retrieve a token:</p>
  
  <pre><code> curl -v -u android-bookmarks:123456 -X POST http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=password&amp;username=User1&amp;grant_type=password&amp;scope=write&amp;client_secret=12345&amp;client_id=android-bookmarks"
  </code></pre>
  
  <p>Response: </p>
  
  <pre><code>{"access_token":"cdafc45f-924a-4f87-8bd0-e3e2bdffa540","token_type":"bearer","refresh_token":"609efba8-edd3-4ea3-be7b-78e449cec0ef","expires_in":43199,"scope":"write"}* Connection #0 to host localhost left intact
  </code></pre>
  
  <p>When I try to access the resource:</p>
  
  <pre><code>curl -G http://localhost:8080/bookmarks -H "Authorization: Bearer cdafc45f-924a-4f87-8bd0-e3e2bdffa540"
  </code></pre>
  
  <p>I get the following response:</p>
  
  <pre><code>{"error":"access_denied","error_description":"Invalid token does not contain resource id (oauth2-resource)"}
  </code></pre>
  
  <p>The Java class setting the resource id:</p>
  
  <pre><code>@Configuration
  @EnableResourceServer
  @EnableAuthorizationServer
  public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter {
  
      public static final String RESOURCE_ID = "bookmarks";
  
      @Autowired
      AuthenticationManagerBuilder authenticationManager;
  
      @Override
      public void configure(AuthorizationServerEndpointsConfigurer endpoints)
          throws Exception {
      endpoints.authenticationManager(new AuthenticationManager() {
          @Override
          public Authentication authenticate(Authentication authentication)
                  throws AuthenticationException {
              return authenticationManager.getOrBuild().authenticate(
                      authentication);
              }
          });
      }
  
      @Override
      public void configure(ClientDetailsServiceConfigurer clients)
          throws Exception {
  
          clients.inMemory()
              .withClient("android-" + RESOURCE_ID)
              .authorizedGrantTypes("password", "authorization_code", "refresh_token")
              .authorities("ROLE_USER")
              .scopes("write")
              .secret("123456")
              .resourceIds(RESOURCE_ID);
      }
  
  }
  </code></pre>
  
  <p>When I change this code to:</p>
  
  <pre><code>clients.inMemory()
          .withClient("android-" + applicationName)
          .authorizedGrantTypes("password", "authorization_code", "refresh_token")
          .authorities("ROLE_USER")
          .scopes("write")
          .secret("123456");
  </code></pre>
  
  <p>I can access the resource with the previously mentioned (curl) commands successfully.</p>