From 295cfd2917da7e55ee7fbb2165ac26b0fa19826b Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 16 Jun 2018 02:28:32 +0300 Subject: [PATCH 1/2] Fixes #218: Allow configuring user component in `AuthAction` --- CHANGELOG.md | 2 +- src/AuthAction.php | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d26c6c8..159edce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ Yii Framework 2 authclient extension Change Log - Enh #203: Updated VKontakte client to use API version 5.0 (Shketkol) - Bug #211: `RsaSha` was not passing `$key` to `openssl_pkey_get_private()` in `generateSignature()` (cfhodges) - Bug #220: Make `OpenIdConnect` client send token as bearer auth instead of querystring parameter (lukos) - +- Enh #218: Allow configuring user component in `AuthAction` (samdark, lab362) 2.1.5 February 08, 2018 ----------------------- diff --git a/src/AuthAction.php b/src/AuthAction.php index 38dd7a5..ec8289e 100644 --- a/src/AuthAction.php +++ b/src/AuthAction.php @@ -11,11 +11,13 @@ 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\User; /** * AuthAction performs authentication via different auth clients. @@ -109,6 +111,12 @@ class AuthAction extends Action */ public $redirectView; + /** + * @var User|array|string the User object or the application component ID of the user component. + * @since 2.1.6 + */ + public $user = 'user'; + /** * @var string the redirect url after successful authorization. */ @@ -118,6 +126,14 @@ class AuthAction extends Action */ private $_cancelUrl; + /** + * @inheritdoc + */ + public function init() + { + parent::init(); + $this->user = Instance::ensure($this->user, User::className()); + } /** * @param string $url successful URL. @@ -165,7 +181,7 @@ public function getCancelUrl() */ protected function defaultSuccessUrl() { - return Yii::$app->getUser()->getReturnUrl(); + return $this->user->getReturnUrl(); } /** @@ -174,7 +190,7 @@ protected function defaultSuccessUrl() */ protected function defaultCancelUrl() { - return Url::to(Yii::$app->getUser()->loginUrl); + return Url::to($this->user->loginUrl); } /** From 886d7836a3685d22e0eda9656051ceaf13fc2b0d Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sun, 14 Oct 2018 10:55:26 +0300 Subject: [PATCH 2/2] Update AuthAction.php --- src/AuthAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AuthAction.php b/src/AuthAction.php index 84aa4cb..32a3650 100644 --- a/src/AuthAction.php +++ b/src/AuthAction.php @@ -113,7 +113,7 @@ class AuthAction extends Action /** * @var User|array|string the User object or the application component ID of the user component. - * @since 2.1.6 + * @since 2.1.8 */ public $user = 'user';