title: Authentificate user with external oAuth2 provider, java spring
body: <p>I am currently playing around with java framework Spring (new with this), trying to build stateless REST API for mobile devices with oAuth2 authorization. In general, i want to implement the folowing steps:</p>
  
  <ul>
  <li>User visit login url, from there he will be redirected by server to oAuth provider to authentificate there</li>
  <li>Social provider return user with code on redirect url, which i fill in previous request as GET parameter</li>
  <li>In redirect url i catch the code, exchange it for data from social provider, and if data is valid, i find user in my database, associated with this data (by social id, for example) and generate for user my token and return it.</li>
  <li>On all requests later client give me this token in HTTP header and i find user by this token (already implements with spring security filters)</li>
  </ul>
  
  <p>Thats all, all i need from social provider it is to authentificate user, but i didnt find easy examples for solving this problem - everywhere huge libs with tons of abstraction, trying to build more complex security layer for me then i want to.</p>
  
  <p>Can someone give me code examples or links to explore with easy solutions of this easy problem with spring tools, preferable in java config? (getting user data from external oAuth2 provider)</p>