PHP code example of maer / google-auth

1. Go to this page and download the library: Download maer/google-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maer / google-auth example snippets


'providers' => array(
    'Maer\GoogleAuth\ServiceProvider',
)

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('[email protected]', '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('[email protected]'),
);

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();

});
bash
$ php artisan config:publish maer/google-auth