This module gives you the option to let you (and your users) log in with their Google account on your Laravel application.
This is initially used to let only people log in from certain workspaces. But can be enabled to let everyone log in.
Using Composer
composer require statikbe/laravel-google-authenticate
The package will automatically register itself.
You can publish the migration with the following command:
php artisan vendor:publish --provider="Statikbe\GoogleAuthenticate\GoogleAuthenticateServiceProvider" --tag="google-migrations"
To add the needed columns to your database run:
php artisan migrate
Add the use HasGoogleAuth
trait in your User.php
class.
This will provide the necessary fillable options to your User.
In your .env file you should include the following keys:
GOOGLE_CLIENT_ID="YOUR_GOOGLE_CLIENT_ID"
GOOGLE_CLIENT_SECRET="YOUR_GOOGLE_CLIENT_SECRET"
CALLBACK_URL_GOOGLE="https://www.domain.com/login/google/callback"
The next step is to add the following lines in your services.php
config file
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL_GOOGLE'),
],
Info on how to create a Google Auth Client id and secret can be found on their documentation page.
Finally, you can add google login route to your login and register views: {{ route('google.auth.login') }}
.
Publish the config file
php artisan vendor:publish --provider="Statikbe\\GoogleAuthenticate\\GoogleAuthenticateServiceProvider" --tag="google-config"
You can change the email domains that can login using Google. The three available options are:
allowed
-array: only the domains in this array can login using Googledisabled
-array: domains in this array can not login using Google- Empty / null: all domains can use the Google login
'domains' => [
//'allowed' => ['statik.com'],
//'disabled' => ['google.com'],
],
You can customize how a user is saved. The config array user_columns
will create the fillable data for your user.
The array keys are your user column names, the array values are what should be stored. (Make sure the value is an array).
You can add multiple values per key, these will be glued together.
The following values would be filled by google's returned data, before being glued.
const GOOGLE_VALUES = [
'name',
'email_verified',
'email',
'given_name',
'family_name',
'picture',
'nickname',
'locale',
];
For example in your config:
'user_columns' => [
'name' => ['name', ' (', 'locale', ')'] // John Doe (en)
'email_verified_at' => ['email_verified'], // 2019-10-23 14:31:50
'email' => ['email'], // [email protected]
'other data' => ['blablabla'], // blablabla
]
You can publish the views and translations files using:
php artisan vendor:publish --provider="Statikbe\\GoogleAuthenticate\\GoogleAuthenticateServiceProvider" --tag="google-views"
and
php artisan vendor:publish --provider="Statikbe\\GoogleAuthenticate\\GoogleAuthenticateServiceProvider" --tag="google-lang"
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License file for more information.