diff --git a/extensions/authclient/clients/GooglePlus.php b/extensions/authclient/clients/GooglePlus.php new file mode 100644 index 00000000000..9947eca39a3 --- /dev/null +++ b/extensions/authclient/clients/GooglePlus.php @@ -0,0 +1,60 @@ + [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'google' => [ + * 'class' => 'yii\authclient\clients\GooglePlus', + * 'clientId' => 'google_client_id', + * 'clientSecret' => 'google_client_secret', + * ], + * ], + * ] + * ... + * ] + * ~~~ + * + * @see GoogleOAuth + * @see yii\authclient\widgets\GooglePlusButton + * @see https://developers.google.com/+/web/signin + * + * @author Paul Klimov + * @since 2.0 + */ +class GooglePlus extends GoogleOAuth +{ + /** + * @inheritdoc + */ + protected function defaultReturnUrl() + { + return 'postmessage'; + } + + /** + * @inheritdoc + */ + protected function defaultViewOptions() + { + return [ + 'widget' => [ + 'class' => 'yii\authclient\widgets\GooglePlusButton' + ], + ]; + } +} \ No newline at end of file diff --git a/extensions/authclient/widgets/GoogleSignInButton.php b/extensions/authclient/widgets/GooglePlusButton.php similarity index 72% rename from extensions/authclient/widgets/GoogleSignInButton.php rename to extensions/authclient/widgets/GooglePlusButton.php index ccbccde4db8..c6aab917b36 100644 --- a/extensions/authclient/widgets/GoogleSignInButton.php +++ b/extensions/authclient/widgets/GooglePlusButton.php @@ -7,7 +7,7 @@ namespace yii\authclient\widgets; -use yii\authclient\clients\GoogleOAuth; +use yii\authclient\clients\GooglePlus; use yii\base\InvalidConfigException; use yii\base\Widget; use yii\helpers\Html; @@ -15,10 +15,10 @@ use yii\web\View; /** - * GoogleSignInButton renders Google+ sign-in button. - * This widget is designed to interact with [[GoogleOAuth]]. + * GooglePlusButton renders Google+ sign-in button. + * This widget is designed to interact with [[GooglePlus]]. * - * @see GoogleOAuth + * @see GooglePlus * @see https://developers.google.com/+/web/signin/ * * @property string|array $callback @@ -26,10 +26,10 @@ * @author Paul Klimov * @since 2.0 */ -class GoogleSignInButton extends Widget +class GooglePlusButton extends Widget { /** - * @var GoogleOAuth google auth client instance. + * @var GooglePlus google auth client instance. */ public $client; /** @@ -72,8 +72,8 @@ public function getCallback() */ public function init() { - if (!($this->client instanceof GoogleOAuth)) { - throw new InvalidConfigException('"' . $this->className() . '::client" must be instance of "' . GoogleOAuth::className() . '"'); + if (!($this->client instanceof GooglePlus)) { + throw new InvalidConfigException('"' . $this->className() . '::client" must be instance of "' . GooglePlus::className() . '"'); } } @@ -86,7 +86,12 @@ public function run() return $this->renderButton(); } - protected function generateCallback($url = null) + /** + * Generates JavaScript callback function, which will be used to handle auth response. + * @param array $url auth callback URL. + * @return string JavaScript function name. + */ + protected function generateCallback($url = []) { if (empty($url)) { $url = ['auth', 'authclient' => $this->client->id]; @@ -102,9 +107,21 @@ protected function generateCallback($url = null) $js = << 'single_host_origin', 'data-requestvisibleactions' => null, 'data-scope' => $this->client->scope, + 'data-accesstype' => 'offline', + 'data-width' => 'iconOnly', + //'data-approvalprompt' => 'force', ], $this->buttonHtmlOptions );