Commit 3c8c8551 by Paul Klimov

'GoogleOAuth' auth client added.

parent a286f309
...@@ -29,7 +29,7 @@ class AuthAction extends Action ...@@ -29,7 +29,7 @@ class AuthAction extends Action
/** /**
* @var string name of the GET param, which is used to passed auth client id to this action. * @var string name of the GET param, which is used to passed auth client id to this action.
*/ */
public $clientIdGetParamName = 'client_id'; public $clientIdGetParamName = 'authclient';
/** /**
* @var callable PHP callback, which should be triggered in case of successful authentication. * @var callable PHP callback, which should be triggered in case of successful authentication.
*/ */
...@@ -119,19 +119,20 @@ class AuthAction extends Action ...@@ -119,19 +119,20 @@ class AuthAction extends Action
} }
/** /**
* @param mixed $provider * @param mixed $client auth client instance.
* @throws \yii\base\NotSupportedException * @return \yii\web\Response response instance.
* @throws \yii\base\NotSupportedException on invalid client.
*/ */
protected function auth($provider) protected function auth($client)
{ {
if ($provider instanceof OpenId) { if ($client instanceof OpenId) {
return $this->authOpenId($provider); return $this->authOpenId($client);
} elseif ($provider instanceof OAuth2) { } elseif ($client instanceof OAuth2) {
return $this->authOAuth2($provider); return $this->authOAuth2($client);
} elseif ($provider instanceof OAuth1) { } elseif ($client instanceof OAuth1) {
return $this->authOAuth1($provider); return $this->authOAuth1($client);
} else { } else {
throw new NotSupportedException('Provider "' . get_class($provider) . '" is not supported.'); throw new NotSupportedException('Provider "' . get_class($client) . '" is not supported.');
} }
} }
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\clients;
use yii\authclient\OAuth2;
/**
* GoogleOAuth allows authentication via Google OAuth.
* In order to use Google OAuth you must register your application at [[https://code.google.com/apis/console#access]].
*
* @see https://code.google.com/apis/console#access
* @see https://developers.google.com/google-apps/contacts/v3/
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class GoogleOAuth extends OAuth2
{
/**
* @inheritdoc
*/
public function __construct($config = [])
{
$config = array_merge(
[
'clientId' => 'anonymous',
'clientSecret' => 'anonymous',
'authUrl' => 'https://accounts.google.com/o/oauth2/auth',
'tokenUrl' => 'https://accounts.google.com/o/oauth2/token',
'apiBaseUrl' => 'https://www.googleapis.com/oauth2/v1',
'scope' => implode(' ', [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
]),
],
$config
);
parent::__construct($config);
}
/**
* @inheritdoc
*/
protected function initUserAttributes()
{
$attributes = $this->api('userinfo', 'GET');
return $attributes;
}
}
\ No newline at end of file
...@@ -40,7 +40,7 @@ class Choice extends Widget ...@@ -40,7 +40,7 @@ class Choice extends Widget
* @var string name of the GET param , which should be used to passed auth client id to URL * @var string name of the GET param , which should be used to passed auth client id to URL
* defined by {@link baseAuthUrl}. * defined by {@link baseAuthUrl}.
*/ */
public $clientIdGetParamName = 'client_id'; public $clientIdGetParamName = 'authclient';
/** /**
* @var array the HTML attributes that should be rendered in the div HTML tag representing the container element. * @var array the HTML attributes that should be rendered in the div HTML tag representing the container element.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment