Skip to content

Commit

Permalink
Updated namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vityachis committed Apr 2, 2019
1 parent 70c9194 commit f47c677
Show file tree
Hide file tree
Showing 53 changed files with 164 additions and 152 deletions.
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "yiisoft/yii2-authclient",
"name": "vityachis/yii2-authclient",
"description": "External authentication via OAuth and OpenID for the Yii framework",
"keywords": ["yii2", "OAuth", "OpenID", "OpenID Connect", "auth", "api"],
"type": "yii2-extension",
Expand Down Expand Up @@ -33,11 +33,8 @@
}
],
"autoload": {
"psr-4": { "yii\\authclient\\": "src" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"psr-4": {
"vityachis\\authclient\\": "src"
}
}
}
26 changes: 16 additions & 10 deletions src/AuthAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use Yii;
use yii\base\Action;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\base\NotSupportedException;
use yii\di\Instance;
use yii\helpers\Url;
use yii\web\Response;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use Yii;
use yii\web\Response;
use yii\web\User;

/**
Expand All @@ -32,7 +32,7 @@
* {
* return [
* 'auth' => [
* 'class' => 'yii\authclient\AuthAction',
* 'class' => 'vityachis\authclient\AuthAction',
* 'successCallback' => [$this, 'successCallback'],
* ],
* ]
Expand All @@ -50,7 +50,7 @@
* This action handles the redirection and closing of popup window correctly.
*
* @see Collection
* @see \yii\authclient\widgets\AuthChoice
* @see \vityachis\authclient\widgets\AuthChoice
*
* @property string $cancelUrl Cancel URL.
* @property string $successUrl Successful URL.
Expand Down Expand Up @@ -125,7 +125,6 @@ class AuthAction extends Action
*/
private $_cancelUrl;


/**
* @inheritdoc
*/
Expand Down Expand Up @@ -200,7 +199,7 @@ public function run()
{
$clientId = Yii::$app->getRequest()->getQueryParam($this->clientIdGetParamName);
if (!empty($clientId)) {
/* @var $collection \yii\authclient\Collection */
/* @var $collection \vityachis\authclient\Collection */
$collection = Yii::$app->get($this->clientCollection);
if (!$collection->hasClient($clientId)) {
throw new NotFoundHttpException("Unknown auth client '{$clientId}'");
Expand Down Expand Up @@ -287,11 +286,11 @@ public function redirect($url, $enforceRedirect = true)
}

$viewData = [
'url' => $url,
'url' => $url,
'enforceRedirect' => $enforceRedirect,
];

$response = Yii::$app->getResponse();
$response = Yii::$app->getResponse();
$response->content = Yii::$app->getView()->renderFile($viewFile, $viewData);

return $response;
Expand All @@ -307,6 +306,7 @@ public function redirectSuccess($url = null)
if ($url === null) {
$url = $this->getSuccessUrl();
}

return $this->redirect($url);
}

Expand All @@ -320,6 +320,7 @@ public function redirectCancel($url = null)
if ($url === null) {
$url = $this->getCancelUrl();
}

return $this->redirect($url, false);
}

Expand All @@ -333,10 +334,11 @@ public function redirectCancel($url = null)
protected function authOpenId($client)
{
$request = Yii::$app->getRequest();
$mode = $request->get('openid_mode', $request->post('openid_mode'));
$mode = $request->get('openid_mode', $request->post('openid_mode'));

if (empty($mode)) {
$url = $client->buildAuthUrl();

return Yii::$app->getResponse()->redirect($url);
}

Expand Down Expand Up @@ -371,13 +373,15 @@ protected function authOAuth1($client, $authUrlParams = [])
if (($oauthToken = $request->get('oauth_token', $request->post('oauth_token'))) !== null) {
// Upgrade to access token.
$client->fetchAccessToken($oauthToken);

return $this->authSuccess($client);
}

// Get request token.
$requestToken = $client->fetchRequestToken();
// Get authorization URL.
$url = $client->buildAuthUrl($requestToken, $authUrlParams);

// Redirect to authorization URL.
return Yii::$app->getResponse()->redirect($url);
}
Expand Down Expand Up @@ -416,10 +420,12 @@ protected function authOAuth2($client, $authUrlParams = [])
if (!empty($token)) {
return $this->authSuccess($client);
}

return $this->authCancel($client);
}

$url = $client->buildAuthUrl($authUrlParams);

return Yii::$app->getResponse()->redirect($url);
}
}
4 changes: 2 additions & 2 deletions src/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use Yii;
use yii\base\Component;
Expand Down Expand Up @@ -94,7 +94,7 @@ abstract class BaseClient extends Component implements ClientInterface
/**
* @var StateStorageInterface|array|string state storage to be used.
*/
private $_stateStorage = 'yii\authclient\SessionStateStorage';
private $_stateStorage = 'vityachis\authclient\SessionStateStorage';


/**
Expand Down
20 changes: 13 additions & 7 deletions src/BaseOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use Yii;
use yii\base\Exception;
use yii\base\InvalidParamException;
use Yii;
use yii\httpclient\Request;

/**
Expand Down Expand Up @@ -67,7 +67,6 @@ abstract class BaseOAuth extends BaseClient
*/
private $_signatureMethod = [];


/**
* @param string $returnUrl return URL
*/
Expand All @@ -84,6 +83,7 @@ public function getReturnUrl()
if ($this->_returnUrl === null) {
$this->_returnUrl = $this->defaultReturnUrl();
}

return $this->_returnUrl;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public function getSignatureMethod()
public function setHttpClient($httpClient)
{
if (is_object($httpClient)) {
$httpClient = clone $httpClient;
$httpClient = clone $httpClient;
$httpClient->baseUrl = $this->apiBaseUrl;
}
parent::setHttpClient($httpClient);
Expand All @@ -154,8 +154,9 @@ public function setHttpClient($httpClient)
*/
protected function createHttpClient($reference)
{
$httpClient = parent::createHttpClient($reference);
$httpClient = parent::createHttpClient($reference);
$httpClient->baseUrl = $this->apiBaseUrl;

return $httpClient;
}

Expand All @@ -174,8 +175,8 @@ protected function defaultReturnUrl()
protected function defaultRequestOptions()
{
return [
'userAgent' => Yii::$app->name . ' OAuth ' . $this->version . ' Client',
'timeout' => 30,
'userAgent' => Yii::$app->name . ' OAuth ' . $this->version . ' Client',
'timeout' => 30,
'sslVerifyPeer' => false,
];
}
Expand All @@ -190,6 +191,7 @@ protected function createSignatureMethod(array $signatureMethodConfig)
if (!array_key_exists('class', $signatureMethodConfig)) {
$signatureMethodConfig['class'] = signature\HmacSha1::className();
}

return Yii::createObject($signatureMethodConfig);
}

Expand All @@ -203,6 +205,7 @@ protected function createToken(array $tokenConfig = [])
if (!array_key_exists('class', $tokenConfig)) {
$tokenConfig['class'] = OAuthToken::className();
}

return Yii::createObject($tokenConfig);
}

Expand Down Expand Up @@ -240,6 +243,7 @@ protected function composeUrl($url, array $params = [])
}
$url .= http_build_query($params, '', '&', PHP_QUERY_RFC3986);
}

return $url;
}

Expand All @@ -266,6 +270,7 @@ protected function restoreAccessToken()
$token = $this->refreshAccessToken($token);
}
}

return $token;
}

Expand All @@ -281,6 +286,7 @@ public function createApiRequest()
{
$request = $this->createRequest();
$request->on(Request::EVENT_BEFORE_SEND, [$this, 'beforeApiRequestSend']);

return $request;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

/**
* ClientInterface declares basic interface all Auth clients should follow.
Expand Down
11 changes: 5 additions & 6 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use Yii;
use yii\base\Component;
use yii\base\InvalidParamException;
use Yii;

/**
* Collection is a storage for all auth clients in the application.
Expand All @@ -19,15 +19,15 @@
* ```php
* 'components' => [
* 'authClientCollection' => [
* 'class' => 'yii\authclient\Collection',
* 'class' => 'vityachis\authclient\Collection',
* 'clients' => [
* 'google' => [
* 'class' => 'yii\authclient\clients\Google',
* 'class' => 'vityachis\authclient\clients\Google',
* 'clientId' => 'google_client_id',
* 'clientSecret' => 'google_client_secret',
* ],
* 'facebook' => [
* 'class' => 'yii\authclient\clients\Facebook',
* 'class' => 'vityachis\authclient\clients\Facebook',
* 'clientId' => 'facebook_client_id',
* 'clientSecret' => 'facebook_client_secret',
* ],
Expand Down Expand Up @@ -56,7 +56,6 @@ class Collection extends Component
*/
private $_clients = [];


/**
* @param array $clients list of auth clients
*/
Expand Down
2 changes: 1 addition & 1 deletion src/InvalidResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use yii\base\Exception;

Expand Down
4 changes: 2 additions & 2 deletions src/OAuth1.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use Yii;
use yii\base\InvalidParamException;
Expand All @@ -18,7 +18,7 @@
* In order to acquire access token perform following sequence:
*
* ```php
* use yii\authclient\OAuth1;
* use vityachis\authclient\OAuth1;
* use Yii;
*
* // assuming class MyAuthClient extends OAuth1
Expand Down
8 changes: 5 additions & 3 deletions src/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use Yii;
use yii\helpers\Json;
Expand All @@ -17,7 +17,7 @@
* In oder to acquire access token perform following sequence:
*
* ```php
* use yii\authclient\OAuth2;
* use vityachis\authclient\OAuth2;
*
* // assuming class MyAuthClient extends OAuth2
* $oauthClient = new MyAuthClient();
Expand Down Expand Up @@ -293,8 +293,9 @@ public function authenticateUser($username, $password, $params = [])
/**
* Authenticates user directly using JSON Web Token (JWT).
* @see https://tools.ietf.org/html/rfc7515
*
* @param string $username
* @param \yii\authclient\signature\BaseMethod|array $signature signature method or its array configuration.
* @param \vityachis\authclient\signature\BaseMethod|array $signature signature method or its array configuration.
* If empty - [[signatureMethod]] will be used.
* @param array $options additional options. Valid options are:
*
Expand All @@ -303,6 +304,7 @@ public function authenticateUser($username, $password, $params = [])
* - signatureKey: string, signature key to be used, if not set - [[clientSecret]] will be used.
*
* @param array $params additional request params.
*
* @return OAuthToken access token.
* @since 2.1.3
*/
Expand Down
2 changes: 1 addition & 1 deletion src/OAuthToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient;
namespace vityachis\authclient;

use yii\base\BaseObject;

Expand Down
Loading

0 comments on commit f47c677

Please sign in to comment.