title: OAuth flow, iPhone -> Rails -> Facebook
body: <p>I'm building an app with both a web client and a iPhone client.</p>
  
  <p>On the web client I authenticate users through Facebook with Omniauth, the user can then post actions on the app to Facebook. That works good.</p>
  
  <p>I'm having some problem implementing the Auth flow from the iPhone application.</p>
  
  <p>I've set up Doorkeeper in the rails app as an OAuth provider. Although I'm not sure how the authentication flow should be implemented.</p>
  
  <p>I've come up with this:
  The user can log in to Facebook in the iPhone and get a token. The idea is then to send the token, along with the Facebook uid to the rails app, store it, and authenticate the user with Omniauth. Once the user is authenticated generate a token with Doorkeeper and send it back to the iPhone app.</p>
  
  <p>If it's the first time the user authenticates against the rails app, a new user will be created.</p>
  
  <p>The user can then do actions against a JSON-api and the rails app will take care of the Facebook integration since the Facebook token is stored on the user record.</p>
  
  <p>The application will also span over several domains so I'll need to have multiple Doorkeeper applications registered to provide different callback uri's.</p>
  
  <p>Does this seem like a viable solution? 
  Is it secure? 
  Is there alternative flows / approaches?</p>
  
  <p>Thanks.</p>