maer / google-auth
Laravel 4 wrapper for the league/oauth2-client package. Simple white/blacklist specific e-mails or entire domains.
Requires
- php: >=5.4.0
- illuminate/support: ~4.1
- league/oauth2-client: 0.3.0
This package is auto-updated.
Last update: 2022-02-01 12:33:55 UTC
README
Add Google auth quick and painless in your Laravel 4 application. It is basically a wrapper for the thephpleague/oauth2-client package. The original package is dead simple to use, but this package adds a simple access control.
You can decide which Google accounts/domains are allowed or blocked. Well, I have used this several times anyway and it's been handy. It's as easy as eating pancakes!
Installation
Best way is to use composer.
Add the following to your composer.json
:
{
"require": {
"maer/google-auth": "dev-master"
}
}
You can, and should, change dev-master
to the current latest.
Setup
Register the service provider in app/config/app.php
:
'providers' => array( 'Maer\GoogleAuth\ServiceProvider', )
Configuration
Publish and edit the configuration file
$ php artisan config:publish maer/google-auth
Edit the app/config/packages/maer/google-auth/config.php
:
return array( 'client_id' => 'YOUR_GOOGLE_CLIENT_ID', 'secret' => 'YOUR_GOOGLE_CLIENT_SECRET', 'callback_url' => 'YOUR_GOOGLE_CLIENT_CALLBACK_URL', /* * Allowed accounts * ------------------------------------- * Enter full e-mail addresses or entire domains. * If empty, all e-mail addresses will be allowed. */ 'allow' => array('your-email@a-domain.com', 'another-domain.com'), /* * Disallowed accounts * ------------------------------------- * Enter full e-mail addresses or entire domains. * If an e-mail or domain is in the allowed and disallowed, * it will be blocked. */ 'disallow' => array('not-allowed@another-domain.com'), );
Usage
This is a simple example of how you use it. You should put this in a controller with depency injection instead.
Route::get('/', function() { echo '<a href="/google-auth">Authorize</a>'; }); Route::get('/google-auth', function(){ // Get the instance of GoogleAuth $Auth = App::make('Maer\GoogleAuth\GoogleAuth'); // This call will redirect the user to Googles Auth screen return $Auth->authorize(); }); Route::get('/google-auth/callback', function(){ // Get the instance of GoogleAuth $Auth = App::make('Maer\GoogleAuth\GoogleAuth'); // If the authorization fails, this method will return null. // Now it's up to you to decide what to do with the user object. $User = $Auth->callback(); // You can also ask for the access token, regardless if you use // the callback-method or not. $token = $Auth->getAccessToken(); });