How to connect a Javascript front end using Facebook Login and a PHP back end through OAuth 2.0?

715 Views Asked by At

I have the following elements:

  • A PHP back-end providing a RESTful API secured with OAuth (FOSOAuthServerBundle with Symfony 2)
  • A Javascript front-end (AngularJS), i.e. an OAuth client.

My goal is to provide users with an authentification page in the front-end, allowing them to log in and access the API through the Javascript.

I do this the following way, according to this article: http://www.bubblecode.net/fr/2013/03/10/comprendre-oauth2/ (unfortunately in French, but if you scroll a bit, the diagrams explaining the standard grant flows are in English):

  1. I provide a form asking the user credentials (login and password)
  2. I use an OAuth Implicit Grant to exchange the user credentials for an access token.

Evertything should work (almost) well so far.


Now, the reason of this question is I want to add Facebook Login to my front-end. What this will give me is a Facebook access token each time a user registers with Facebook Login on my front-end. Ideally, my back-end should:

  • get this token
  • check it against Facebook PHP API in order to validate it
  • retrieve from Facebook PHP API the user Facebook UID
  • compare it to the ones of my app registered users
  • return an access token (this time for my own app, not Facebook) if and only if the Facebook UID matches with one of my registered app users.

My question is: which type of grant should I use to make the transaction between my front-end and my back-end in such a use case (given that it is of course not acceptable to give my Client Secret from a Javascript Client)?

1

There are 1 best solutions below

0
On

Actually, I managed to found the solution. A custom grant should be designed to solve this problem, based on the Implicit Grant (in which the Client Secret is not asked).

However FOSOauthServerBundle does not yet implement grants based on public clients (see https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/issues/266 for more details).