AngularJS + Yii2 REST + OAuth2

Hi All!

I would like to advise with community on the scenario which doesn’t seem to be discussed anywhere earlier but looks rather common nowadays.

I work on hybrid mobile app powered by Ionic framework which assumes AngularJS HTML5 web application in fact. On the server side this is powered by Yii2 REST API and there are also regular Yii2 applications for website’s frontend/backend.

First of all I struggled with mobile user authentication with username/password but this is now fully resolved (thanks to yii2-oauth2-server module - https://github.com/Filsh/yii2-oauth2-server).

Now I am trying to figure out how to properly add to mobile application Facebook/Google authentication as well.

Main difficulty for me is that I definitely want the users authenticated by FB/Google from mobile application to be properly stored in my Yii2 users database.

N.B.: I do not need any further social functionality for now ("Like" buttons etc.), only authorization of user actions in mobile application based on "loggedIn" status.

Can anyone advise me on the proper approach to accomplish this or may be refer to relevant Github repo?

I’m thinking of two possible scenarios:

  1. AngularJS in mobile application utilizes Yii2 AuthClient from the beginning of authentication process and upon successful registration/authentication it somehow utilizes yii2-oauth2-server to get access/refresh tokens (as in regular username/password scenario).

  2. AngularJS mobile application utilizes own libraries for direct FB/Google authentication and upon successful finish of the process somehow stores/updates user’s information in Yii2.

The worst parts are those bold somehow’s which I’m not really sure about… :)

And moreover I think that may be I totally misunderstand OAuth2 approach and this routine should be implemented in totally different way.

I say thank you in advance to anyone who can help me on this!