Browse Source

'GoogleOAuth' auth client added.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
3c8c855145
  1. 23
      extensions/yii/authclient/AuthAction.php
  2. 54
      extensions/yii/authclient/clients/GoogleOAuth.php
  3. 2
      extensions/yii/authclient/widgets/Choice.php

23
extensions/yii/authclient/AuthAction.php

@ -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.
*/
public $clientIdGetParamName = 'client_id';
public $clientIdGetParamName = 'authclient';
/**
* @var callable PHP callback, which should be triggered in case of successful authentication.
*/
@ -119,19 +119,20 @@ class AuthAction extends Action
}
/**
* @param mixed $provider
* @throws \yii\base\NotSupportedException
* @param mixed $client auth client instance.
* @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) {
return $this->authOpenId($provider);
} elseif ($provider instanceof OAuth2) {
return $this->authOAuth2($provider);
} elseif ($provider instanceof OAuth1) {
return $this->authOAuth1($provider);
if ($client instanceof OpenId) {
return $this->authOpenId($client);
} elseif ($client instanceof OAuth2) {
return $this->authOAuth2($client);
} elseif ($client instanceof OAuth1) {
return $this->authOAuth1($client);
} else {
throw new NotSupportedException('Provider "' . get_class($provider) . '" is not supported.');
throw new NotSupportedException('Provider "' . get_class($client) . '" is not supported.');
}
}

54
extensions/yii/authclient/clients/GoogleOAuth.php

@ -0,0 +1,54 @@
<?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;
}
}

2
extensions/yii/authclient/widgets/Choice.php

@ -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
* 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.
*/

Loading…
Cancel
Save