Social Meal - social application - Add login by Facebook
Login by Facebook
In this contribution I focused about possibility to login to this application by facebook account.
To this moment my API part has only one possibility to authorization. User has to create new account in this application. I decided with my friend who is making a android application connected with my server part, that we have to implement a facebook login to our application, what is more in the future we want to more integrated our application with facebook, such like posting to own table, sharing etc. All information ofc will be stored in our database including login time, address ip and other information, which make our application more safety.
screenshot from swagger with this method:
Implementation is divided into several parts. This feature required some changes in code and adding new services, resources and other method.
- screen with commits and pull request from github
As you can see in commits implementation contains:
- add new resources like: resources for login and user data from facebook.
- add facebook service
- add necessary methods in accountControler and services
- add unit test for account service
How it works?
When want to login by Facebook in mobile application, send login request to Facebook. Then he receive facebook access token, this token is sending to our application with login request. We are checking if this user exsist in Facebook data and we send request to get a basic data like email, firstname and surname which are required in our application. Next step is checking if this user exist in our database, if exsist the system will create JWT Tokens and return to user. If user not exist system will create account in our application and return tokens. In next request user have to use tokens from our application to get other resources.
Posted on Utopian.io - Rewarding Open Source Contributors