2017 © Pedro Peláez
 

library google-oauth-laravel4

Optimize artdarek/oauth-4-laravel with Google OAuth 2.0 for laravel 4

image

edisonthk/google-oauth-laravel4

Optimize artdarek/oauth-4-laravel with Google OAuth 2.0 for laravel 4

  • Friday, June 27, 2014
  • by edisonthk
  • Repository
  • 1 Watchers
  • 2 Stars
  • 4,423 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 235 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

Google OAuth for Laravel 4

oauth-4-laravel is a simple laravel 4 Google OAuth 2.0 . It is integrated with Lusitanian/PHPoAuthLib and artdarek/oauth-4-laravel which provides oAuth 2.0 support in PHP 5.3+ for laravel 4., (*1)


Installation

This package is available in packagist.org. You can install it by adding following in composer.json, (*2)

"require": {
    "edisonthk/google-oauth-laravel4": "dev-master"
},

then, install it by, (*3)

composer update

After finish installed, import service provider and alias in app/config/app.php, (*4)

'providers' => array(
    'Edisonthk\GoogleOAuth\GoogleOAuthServiceProvider',
)

 :
 :

'aliases' => array(
    'GoogleOAuth'   => 'Edisonthk\GoogleOAuth\Facade\GoogleOAuth',
)

Configuration & Credentials

Get your client_secret and client_id from Google Developers Console. Then, configure it with laravel. There are 2 options you can configure with it., (*5)

Option 1:

Create config file by artisan command., (*6)

$ php artisan config:publish edisonthk/google-oauth-laravel4

Then, config file will be generated at app/config/packages/edisonthk/google-oauth-laravel4/config.php. Fill it in with your client_secret, cliend_id, redirect_url and scope., (*7)

Option 2:

Create a config file called google-oauth-laravel4.php in app/config directory. Then add following code and fill in your client_secret, cliend_id and redirect_url., (*8)

<?php 

return array( 

    /*
    |--------------------------------------------------------------------------
    | oAuth Config
    |--------------------------------------------------------------------------
    */

    /**
     * Storage
     */
    'storage' => 'Session', 

    /**
     * Consumers
     */
    'consumers' => array(

        /**
         * Google
         */
        'Google' => array(
            'client_id'     => '',
            'client_secret' => '',
            'redirect_url'  => '',
            'scope'         => array(),
        ),      

    )

);

Sample code

On configuration, (*9)

'Google' => array(
    'client_id'     => 'Your Google client ID',
    'client_secret' => 'Your Google Client Secret',
    'redirect_url'  => 'http://www.example.com/success'
    'scope'         => array('userinfo_email', 'userinfo_profile'),
),

On app/routes.php, (*10)

Route::controller('/', 'HomeController');

On app/controllers/HomeController.php, (*11)

<?php

class HomeController extends BaseController {

    public function getIndex()
    {
        $authUrl = GoogleOAuth::getAuthorizationUri();
        $message = "<a href='$authUrl'>Login with Google</a>";

        die($message);
    }

    public function getSuccess()
    {
        $googleService = GoogleOAuth::consumer();

        if(Input::has("code")){
            $code = Input::get("code");
            $googleService->requestAccessToken($code);
            return Redirect::to("/success");
        }

        if(!GoogleOAuth::hasAuthorized()){
            die("Not authorized yet");
        }


        $result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );

        $message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
        die($message. "<br/>");


    }

    public function getLogout()
    {
        GoogleOAuth::logout();
        return Redirect::to("/");
    }


}

The Versions

27/06 2014

dev-master

9999999-dev https://github.com/edisonthk/google-oauth-laravel4

Optimize artdarek/oauth-4-laravel with Google OAuth 2.0 for laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Heng LikWee

laravel php oauth google lusitanian

22/06 2014

1.0.5

1.0.5.0 https://github.com/edisonthk/google-oauth-laravel4

Optimize artdarek/oauth-4-laravel with Google OAuth 2.0 for laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Heng LikWee

laravel php oauth google lusitanian

07/02 2014

1.0.4

1.0.4.0 https://github.com/artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Artdarek

laravel php oauth lusitanian

19/11 2013

1.0.3

1.0.3.0 https://github.com/artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Artdarek

laravel php oauth lusitanian

12/11 2013

1.0.2

1.0.2.0 https://github.com/artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Artdarek

laravel php oauth lusitanian

16/10 2013

1.0.1

1.0.1.0 https://github.com/artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Artdarek

laravel php oauth lusitanian

18/09 2013

1.0.0

1.0.0.0 https://github.com/artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Artdarek

laravel php oauth lusitanian