diff --git a/src/AuthAction.php b/src/AuthAction.php index 38dd7a5..52158d2 100644 --- a/src/AuthAction.php +++ b/src/AuthAction.php @@ -118,6 +118,19 @@ class AuthAction extends Action */ private $_cancelUrl; + /** + * @var string the ID of user component + * user component ID, which might be set in different module + */ + public $userComponentID; + + /** + * @var instance of \yii\web\User + * user component, which is build via [[userComponentID]] property + * if [[userComponentID]] propety not set, then default app user (Yii::$app->getUser()) component will be used + */ + private $_user; + /** * @param string $url successful URL. @@ -165,7 +178,7 @@ public function getCancelUrl() */ protected function defaultSuccessUrl() { - return Yii::$app->getUser()->getReturnUrl(); + return $this->_user->getReturnUrl(); } /** @@ -174,7 +187,7 @@ protected function defaultSuccessUrl() */ protected function defaultCancelUrl() { - return Url::to(Yii::$app->getUser()->loginUrl); + return Url::to($this->_user->loginUrl); } /** @@ -191,6 +204,12 @@ public function run() } $client = $collection->getClient($clientId); + $this->_user = (!empty($this->userComponentID) && is_string($this->userComponentID)) ? Yii::createObject(["class" => $this->userComponentID]) : Yii::$app->getUser() ; + + if (!($this->_user instanceof \yii\web\User)) { + throw new InvalidConfigException('"' . get_class($this) . '::$user" should be a instance of \yii\web\User.'); + } + return $this->auth($client); }