title: For a hybrid SSO scenario using the Facebook iOS SDK, what's the best way generating a password/key for our own custom user records?
body: <p>So my intention is to have a login in my iOS app that allows for either our standard email/pwd registration, or login with Facebook.  We are also creating rest services to get application info for a given user, e.g. https://url/getPosts/[userId]?userPwd=foo</p>
  
  <p>I've implemented SSO with fb in a web application before but I have some concerns about the security of authentication in a iOS client scenario.  The key difference from what I've done before is that in a web app, I was making a server to server call to Facebook to get the access token so I was reasonably assured that the user was authenticated and the web server made privileged calls to the database.  In the iOS case, I have the mobile client app making the Facebook iOS authentication request itself and the server has to somehow trust that this user from the client app is indeed authenticated against the matching user record in our database.</p>
  
  <p>My question is how do I generate a durable and secret unique key from the iOS SDK so that I can create and associate a matching user record in our database for users that authenticate only with Facebook.  I want this to be seamless so the user would not have to manually fill out another form, and we would just automatically create this matching user record in our db. </p>
  
  <p>I could insert a record into my own users table when they fbDidLogin with Facebook, using the Facebook Id as the unique identifier, and the fb access token as the pseudo password/key for my own user record.  I would have to validate the access token with Facebook to make sure it's valid before saving it as a password for the user (the user would never see this password, it would just be passed by the client app during api calls).  That way when the user makes a call to our own rest api via the iPhone app we can authenticate and authorize using this secret/pwd/key.  </p>
  
  <p>An alternative that would make this whole question moot is to just handle the authorization logic on the client app, and check that there is a valid fb session before making calls to our own apis which I secure with just a single application-wide secret, but that doesn't seem as secure since getting that one secret gives authorization to data on all users.  I'd rather authorize at an individual user level.  Is that the right choice?  Am I being paranoid about iOS security?</p>
  
  <p>The fb access token expires so that might not seem durable, however if I enable offline access that token won't expire but creates a scarier looking oauth dialog window.  An alternative to the access token is to hash the fb Id with an application secret key on the iOS client, and use that as the Facebook user's password in our db.  However, that again is a single secret key that could perhaps be reverse compiled from the iOS client app?</p>