I really can't find a clear answer / approach to the following problems / questions:
I'd like to have a Symfony2 backend, probably with FOSRestBundle, which only returns JSON. The frontend will be written in AngularJS.
The user should either be able to register / login an account only for my website (option #1) or login via an existing OAuth account, like Google or Xing (option #2). Of course the authentication should / needs be stateless.
Since most of the examples of how to authenticate RESTFul in symfony are completely in php (so even backend and frontend are seperated, the frontend is still PHP) I'm really having a hard time to figure out how I can achieve the two options above. My current thoughts for the backend are:
- FOSRestBundle for handling requests / responses
- FOSUserBundle for register, login, password reset, etc. for new users
My questions are:
- How can I authenticate a normal user (FOSUserBundle) stateless (option #1)? I couldn't find anything in the documentation about how to use the FOSUserBundle with a separate frontend. Or is there a better bundle for this scenario?
- If the user wants to authenticate via OAuth2 Provider (option #2) which part of the app (frontend or backend) authenticates against the OAuthProvider (e.g. Google)? I though about authenticate in AngularJS (e.g. via oauth-ng module), getting the AuthToken and send it to the backend, where I match the user with his id I (hopefully) get from the OAuthProvider.
Besides the question, if this approach is correct in the first place, I really need some hints about how to achieve this in symfony. I know, that one can customize almost anything in symfony (CustomUserProvicer, CustomAuthentication, etc.) but before reading into those details, maybe there is already a simple way to solve my problems. I mean, I can't be the only one who wants this...
If anything is unclear, just ask!