Adapter capabilities

 User authenticationYES
 User profileYES
 User contacts listYES
 User activity streamNO
 Post to user wall / update statusNO
 Access provider APIYES

Adapter specifications

 ID Google
 Protocol OAuth2
 IDp URL http://www.google.com/
 Keys registeration https://code.google.com/apis/console/
 Dev documentation http://code.google.com/intl/fr/apis/accounts/docs/OAuth2.html
 Since HybridAuth 1.0.1
 Wrapper ./Hybrid/Providers/Google.php
Callback URL http://mywebsite.com/path_to_hybridauth/?hauth.done=Google

Configuration & Usage


<?php 
    $config = array( 
      "base_url" => "http://mywebsite.com/path/to/hybridauth/",  
      "providers" => array (
        "Google" => array ( 
          "enabled" => true,
          "keys"    => array ( "id" => "PUT_YOURS_HERE", "secret" => "PUT_YOURS_HERE" ), 
          "scope"           => "https://www.googleapis.com/auth/userinfo.profile ". // optional
                               "https://www.googleapis.com/auth/userinfo.email"   , // optional
          "access_type"     => "offline",   // optional
          "approval_prompt" => "force",     // optional
          "hd"              => "domain.com" // optional
    )));
    
    require_once( "/path/to/hybridauth/Hybrid/Auth.php" );
    
    $hybridauth = new Hybrid_Auth( $config );
    
    $adapter = $hybridauth->authenticate( "Google" );  
    
    $user_profile = $adapter->getUserProfile(); 

For Google you can configure several extra options: (refer to https://developers.google.com/accounts/docs/OAuth2WebServer#formingtheurl")

  • scope: A space delimited set of permissions the application requests. Indicates the Google API access your application is requesting.
  • access_type: Can be "online or offline". By default its set to "offline". Indicates if your application needs to access a Google API when the user is not present at the browser.
  • approval_prompt: Can be "force or auto". By default its set to "auto". Indicates if the user should be re-prompted for consent. The default is auto, so a given user should only see the consent page for a given set of scopes the first time through the sequence. If the value is force, then the user sees a consent page even if they have previously given consent to your application for a given set of scopes.
  • hd: Can be used to force users from a specific domain.

Registering application


1. Go to https://code.google.com/apis/console/ and create a new project.

2. Go to API Access under API Project. After that click on Create an OAuth 2.0 client ID to create a new application.

3. A pop-up named "Create Client ID" will appear, fill out any required fields such as the application name and description.

4. Click on Next.

5. On the popup set Application type to Web application and switch to advanced settings by clicking on (more options).

6. Provide this URL as the Callback URL for your application: http://mywebsite.com/path_to_hybridauth/?hauth.done=Google

7. Once you have registered, copy and past the created application credentials (Client ID and Secret) into the HybridAuth config file.