I am looking forward to integrate logging in users using Facebook's authentication. I have my app protected by OpenAM and the users are already registered there. I have my own login page and would not like to move this to OpenAM and retain it in my app. As of now, I am using REST calls to authenticate users in OpenAM. Now, I want to integrate login using Facebook. My idea of implementation is as following:
- User logs in using original credentials and is authenticated in OpenAM.
- User is asked to associate his/her Facebook account with the OpenAM account.
- User authenticates his/her Facebook account (https://www.facebook.com/dialog/oauth?app_id={app-id-as-created-in-fb-developers-console}&redirect_uri={my-rest-service}).
- This will return the code and that can be used to recheck against Facebook to ensure that the user was authenticated against my app and this is not a hacker intervention (http://graph.facebook.com/debug_token?%20input_token={code-returned-from-facebook}&access_token={my-app's-access-token}. The response will contain the app ID that can be verified against my App's ID. On success, I shall call OpenAM to associate the user in OpenAM with his/her Facebook credentials (Not sure what all to use here.)
- Next, whenever the user wants to login, he/she can use Facebook login where in the redirect URL would be my REST service and the code returned from Facebook can be rechecked from Facebook and then OpenAM will be called to authenticate.
My queries:
- I am not sure if this approach is feasible.
- How do I pair an existing user in OpenAM with the Facebook account?
- How do I authenticate the user in OpenAM after Facebook login, with the userID?
- Is the Facebook userID (numeric,returned from Facebook graph in JSON response), unique and permanent?
- I would also want to give the users an option to de-associate the existing Facebook account and associate a new one-how do I do this?
Apologies for asking too many questions, but I am new to OpenAM and OAuth and keen on following the approach I have mentioned above. Thank you.