Adapter capabilities
User authentication | YES |
User profile | YES |
User contacts list | YES |
User activity stream | NO |
Post to user wall / update status | NO |
Access provider API | YES |
Adapter specifications
ID | |
Protocol | OAuth2 |
IDp URL | https://www.google.com/ |
Keys registeration | https://console.developers.google.com/cloud-resource-manager |
Dev documentation | https://developers.google.com/identity/sign-in/web/sign-in |
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" ),
- "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")
-
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
Please note that this section might be outdated in the exact way how to get your application registered on Google.
- Go to the Google Developers Console.
- From the project drop-down, select a project, or create a new one.
- In the sidebar under "API Manager", select Credentials.
- In the Credentials tab, select the New credentials drop-down list, and choose OAuth client ID.
- From the Application type list, choose the Web application.
- Enter a name and provide this URL as Authorized redirect URIs: http://mywebsite.com/path_to_hybridauth/?hauth.done=Google then select Create.
- Once you have registered, copy and past the created application credentials (Client ID and Secret) into the HybridAuth config file.