title: How to use OAuth2RestTemplate?
body: <p>I'm trying to understand how to use a OAuth2RestTemplate object to consume my OAuth2 secured REST service (which is running under a different project and let's assume also on a different server etc...)</p>
  <p>An example of my REST service is:</p>
  <pre><code>http://localhost:8082/app/helloworld
  </code></pre>
  <p>-&gt; Accessing this URL generates an error as I am not authenticated</p>
  <p>To request a token I would go to:</p>
  <pre><code>http://localhost:8082/app/oauth/token?grant_type=password&amp;client_id=restapp&amp;client_secret=restapp&amp;username=**USERNAME**&amp;password=**PASSWORD**
  </code></pre>
  <p>After I receive the token I can then connect to the REST API by using the following URL (example token inserted)</p>
  <pre><code>http://localhost:8082/app/helloworld/?access_token=**4855f557-c6ee-43b7-8617-c24591965206**
  </code></pre>
  <p>Now my question is how do I implement a second application which can consume this OAuth2 secured REST API? I really haven't found any working examples where you provide the user name and password (e.g. coming from a login form) and then a token is generated which can be re-used to get data from the REST API.</p>
  <p>I currently tried something with the following objects:</p>
  <pre><code>BaseOAuth2ProtectedResourceDetails baseOAuth2ProtectedResourceDetails =  new BaseOAuth2ProtectedResourceDetails();
  baseOAuth2ProtectedResourceDetails.setClientId(&quot;restapp&quot;);
  baseOAuth2ProtectedResourceDetails.setClientSecret(&quot;restapp&quot;);
  baseOAuth2ProtectedResourceDetails.setGrantType(&quot;password&quot;);
  // how to set user name and password ???
  
  DefaultAccessTokenRequest accessTokenRequest = new DefaultAccessTokenRequest();
  OAuth2ClientContext oAuth2ClientContext = new DefaultOAuth2ClientContext(accessTokenRequest());
  
  OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(baseOAuth2ProtectedResourceDetails,oAuth2ClientContext);
  </code></pre>
  <p>But this just isn't working :(</p>
  <p>Any ideas, links to working examples or tutorials are greatly appreciated.</p>