what is OAuth ?
OAuth (Open Authorization) is an open standard for token-based authentication and authorization on the Internet. ... OAuth acts as an intermediary on behalf of the end user, providing the service with an access token that authorizes specific account information to be shared. OAuth, allows an end user's account information to be used by third-party services, such as Facebook, without exposing the user's password. OAuth acts as an intermediary on behalf of the end user, providing the service with an access token that authorizes specific account information to be shared.The idea is that you are giving certain permission to accesss your facebook details such as name , id and email , so that facebook can provide informations to sign up, give your profile details.
In this tutorial we are going to experiment this by following these following steps.
Step 01 - create an app with facebook.
To gain access to your facebook profile you need to create an app in developer account.
go to https://developers.facebook.com and register it with your desired name.
after created the app, go to basic settings and fill out the details. If you are using web application from local database, use localhost in app domain and scroll down to find a place to enter your localhost url.
Note : In basic settings APP ID and APP SECRET will be used as passing parameter to get access token.
After that we have to generate token to restrict the permission which others need to access. so that, click tools -> "graph api explorer" -> "get user access" token and select permissions and click "get access token".
Here I selected only email for permission and individually selected each fields by adding nodes.
Above data retrieved by web application. I have implemented this application with login page (fb-login.php) , configure page with APP ID & SECRET ID (conf.php), redirect page to retrieve information (fb-callback.php) and index page to display gathered information (index.php).
NOTE : you need to have Facebook Software Develop Kit to do exclusive functions. go to https://github.com/facebook/php-graph-sdk to download facebook SDK.
Configuration Page ( conf.php)
I create a facebook object and pass app id , secret id as a parameters which we got from the developer side app basic settings.
Login Page ( fb-login.php)
we need to mention the redirect url(http://localhost:OAuth/fb-callback.php) to get retrieved information with permissions.
when user clicks the "login with facebook" it will be redirected to the fb-callback page.
Redirect Page ( fb-callback.php)
After clicked the login, it will ask the permission from user to access their profile. like this
After that It will be redirected to the fb-callback page. we should implement the callback page to get information and token from the server.
By using accessToken I get userdata(ID,firstname.lastname,email) in array and stored it to the session array. fb-callback page opens index.php to display retrieved information.
Finally, we can see ID , first name, last name, email in index page.
Hope you got some useful information regarding OAuth 2.0 from this article. To get quick example about OAuth 2.0 refer example from https://developers.facebook.com/docs/php/howto/example_facebook_login.

















0 comments:
Post a Comment