sergeiten / laravel-passport-facebook-login
Facebook Token Request Grant for Laravel Passport
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 25
pkg:composer/sergeiten/laravel-passport-facebook-login
Requires
- facebook/graph-sdk: ^5.6
- laravel/passport: ^5.0||^6.0||^7.0
README
Provides a new Laravel Passport Grant Client named facebook_login, allowing you to log a user in with just their Facebook Login token.
A new user will be created (and optionally assigned to an role - $user->attachRole(ID)) if the email address doesn't exist.
Installation:
Install with composer composer require sergeiten/laravel-passport-facebook-login. Use major version 1 for Passport 4 and below Laravel 5.6 compatibility.
Versions:
- Laravel 5.6 and Passport 5.0 only supported at this time
Dependencies:
"laravel/passport": "~5.0""facebook/graph-sdk": "~5.6"
Setup:
- Add
SergeiTen\PassportFacebookLogin\FacebookLoginGrantProvider::classto your list of providers afterLaravel\Passport\PassportServiceProvider. - Add
SergeiTen\PassportFacebookLogin\FacebookLoginTraitTrait to yourUsermodel (or whatever model you have configured to work with Passport). - Run
php artisan vendor:publish, this will create aconfig/facebook.phpfile. - Enter your Facebook App details in your
.envfile:FACEBOOK_APP_IDandFACEBOOK_APP_SECRET. - Optional: To automatically attach a role (https://github.com/Zizaco/entrust) to new users, use the 'ATTACH_ROLE' env setting.
Config:
/* |-------------------------------------------------------------------------- | Application |-------------------------------------------------------------------------- | | The facebook ID and secret from the developer's page | */ 'app' => [ 'id' => env('FACEBOOK_APP_ID'), 'secret' => env('FACEBOOK_APP_SECRET'), ], /* |-------------------------------------------------------------------------- | Registration Fields |-------------------------------------------------------------------------- | | The name of the fields on the user model that need to be updated, | if null, they shall not be updated. (valid for name, first_name, last_name) | */ 'registration' => [ 'facebook_id' => env('FACEBOOK_ID_COLUMN', 'facebook_id'), 'email' => env('EMAIL_COLUMN', 'email'), 'password' => env('PASSWORD_COLUMN', 'password'), 'first_name' => env('FIRST_NAME_COLUMN', 'first_name'), 'last_name' => env('LAST_NAME_COLUMN', 'last_name'), 'name' => env('NAME_COLUMN', 'name'), 'attach_role' => env('ATTACH_ROLE', null), 'user_picture' => env('USER_PICTURE', null), ],
How To Use:
- Make a POST request to
https://your-site.com/oauth/token. - The POST body should contain
grant_type=facebook_loginfb_token={token from facebook login}.- client_id
- client_secret
- An
access_tokenandrefresh_tokenwill be returned if successful.
Assumptions:
- Your
Usermodel has the following fields: -
facebook_id
-
nameorfirst_name&last_name
-
email
-
password
-
picturefacebook user picture
Why not use Laravel 5.5's auto-discovery?
We have found that using auto discovery can cause issues as this package relies on Laravel Passport been loaded before this package. Sometimes this doesn't happen, and caused issues as Laravel Passport sets up a singleton we reference.
We hope that one day there will be a fix to Laravel auto-discovery that will allow for dependencies to be handled better.