Krajee

Google Signin Plugin

Thankful to Krajee! BUY A COFFEEor to get more out of us.
The Google Signin button triggers the OAuth 2.0 sign-in flow and will output the authorization result object. You can control granting access, denying access, and closing the authorization dialog to see the results of each action. You can setup the Google Signin button plugin in your view layout file or your view using the instuctions below. Note a valid clientId is needed to display this plugin. Refer Google signin button documentation for details on passing the settings for this plugin.

Refer also the Google signin button attributes for setting various options for this plugin.

Tip

Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)

use kartik\social\GooglePlugin;

/**
 * If any parameters are not passed, the widget will use settings from the social 
 * module wherever possible. For example `clientId`, `pageId`, and `profileId` will
 * be referred from the module settings.
 */
echo GooglePlugin::widget([
    'type'=>GooglePlugin::SIGNIN, 
    'tag'=>'span', 
    'signinOptions'=>['id'=>'signinButton'],
    'settings' => [
        'callback'=>'signinCallback',
        'cookiepolicy' => 'single_host_origin',
        'requestvisibleactions' => 'https://schemas.google.com/AddActivity',
        'scope'=>'https://www.googleapis.com/auth/plus.login'
    ]
]);

/**
 * The callback client script
 */
function signinCallback(authResult) {
  if (authResult['status']['signed_in']) {
    // Update the app to reflect a signed in user
    // Hide the sign-in button now that the user is authorized, for example:
    document.getElementById('signinButton').setAttribute('style', 'display: none');
  } else {
    // Update the app to reflect a signed out user
    // Possible error values:
    //   "user_signed_out" - User is signed-out
    //   "access_denied" - User denied access to your app
    //   "immediate_failed" - Could not automatically log in the user
    console.log('Sign-in state: ' + authResult['error']);
  }
}

Note

You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.

The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.

 
visitors to Krajee Yii2 Demos since 22-May-2017