Download the PHP package keukenmagazijn/laravel-google-authentication without Composer
On this page you can find all versions of the php package keukenmagazijn/laravel-google-authentication. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download keukenmagazijn/laravel-google-authentication
More information about keukenmagazijn/laravel-google-authentication
Files in keukenmagazijn/laravel-google-authentication
Package laravel-google-authentication
Short Description This package provides an easy-to-use Facade for the Google userinfo API using the official google/apiclient package.
License MIT
Informations about the package laravel-google-authentication
Introduction
This package allows users to quickly authenticate using their Google account with Google Identity. You are able to specify a domain the user' account must be in - or you can just allow anyone to register.
The package extends and works together with the default Laravel authentication, but it requires modification and additions to the default tables provided by Laravel.
Installation
Your users table will be reformed and you will have to have the following migration available in your application:
Migrations
If you have already ran the default php artisan make:auth
command you will need to change your columns to uphold the same columns and their types mentioned above.
The package provides the rest of the required migrations, such as user_roles, roles and a google_oauth_tokens_table.
You have the option to create either tables or to create views if your database architecture requires you to do so.
In the latter case you need to configure the configured alias name and the database name itself that you want to source the data from in the
config/google_identity.php
file and you will need to change the migrations.create_views_instead_of_tables
value from false to true
.
Or add the following config keys to your .env
file and configure it with your config values:
Configuration
Once you have configured the migration you will have to publish the configuration file by running php artisan vendor:publish --tag=km
. Be sure to edit the package properly to your environment.
UsesGoogleIdentity trait
Once your package is published you will have to add the Keukenmagazijn\LaravelGoogleAuthentication
Trait to your User model, ie.:
Button rendering and Identity
You can render the authorization button by adding the following code to your blade:
When a user authorizes it will check if the user account is within the whitelisted domains (configured in your config/google_identity.php
file), or if you allowed any domain to register, it will always succeed when permissions are given.
Users authorizing using Google will automatically gain the 'employee' role.
Required entities
The following models/entities should be available in your application.
User.php (this is my example)
GoogleOauthToken.php
Role.php
Google Identity
You need to set-up a route for your Google Identity to call back to, this is done in Google Identity itself.
Once you have those configuration settings, you should now fill add the following data to your .env
file and fill it with the corresponding data:
Routing
The next step is to set-up a get route for the GOOGLE_IDENTITY_REDIRECT_URI
uri.
There is a controller available within the package to handle the callback for you and it will redirect you back to the named route defined as callback_redirect_route_name
in the config/google_identity.php
file.
If you want to customize the callback method you can set-up a custom controller for it and use the GoogleIdentityController
as an example on how to use the GoogleIdentityFacade
.
An example route where GOOGLE_IDENTITY_REDIRECT_URI='http://appurl.extension/identity/callback'
:
All versions of laravel-google-authentication with dependencies
laravel/framework Version ^10.0
google/apiclient Version ^2.2
astrotomic/laravel-translatable Version ^11.3