title: Symfony2 authentication via 3rd Party REST API
body: <p>I'm writing an application using Symfony2 which will interface with the <a href="http://developer.wordnik.com/docs" rel="nofollow noreferrer">Wordnik REST API</a>.</p>
  
  <p>Currently, the Wordnik API does not offer OAuth capabilities, so I have to accept a username and password which I'll then transparently pass to the API interface.</p>
  
  <p>I'd like to integrate this API authentication into Symfony2's security system, but so far I haven't been able to identify what the best implementation route is.</p>
  
  <p>I don't think the <a href="http://symfony.com/doc/2.0/cookbook/security/custom_provider.html" rel="nofollow noreferrer">custom user provider</a> is correct, because the password is not stored in my system. All examples regarding <a href="http://symfony.com/doc/2.0/cookbook/security/custom_authentication_provider.html" rel="nofollow noreferrer">custom authentication providers</a> seem to pertain to the securing of a part of an application <em>as</em> an API, rather than <em>against</em> a REST API.</p>
  
  <p>It's not clear to me to what extent the FOSUserBundle helps to solve this problem either.</p>
  
  <p><em>The ideal flow:</em></p>
  
  <ul>
  <li>User provides credentials.</li>
  <li>Credentials are passed to the 3rd party REST API</li>
  <li>If the credentials are correct:
  
  <ul>
  <li>A corresponding "third party user" Entity is created by my application, if it doesn't exist.</li>
  <li>The user is authenticated using this "third party user" Entity.</li>
  </ul></li>
  </ul>
  
  <p>What is the best way to implement this within a Symfony2 security context?</p>
  
  <p>Thanks!</p>
  
  <p><em>Related Questions:</em></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/14264066/problems-configuring-user-authentication-by-external-api-on-symfony2">Problems configuring user authentication by external API on Symfony2</a></li>
  </ul>