Skip to content

Commit bebf74b

Browse files
authored
Fixes #218: Allow configuring user component in AuthAction
1 parent 463954a commit bebf74b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Yii Framework 2 authclient extension Change Log
44
2.1.8 under development
55
-----------------------
66

7+
- Enh #218: Allow configuring user component in `AuthAction` (samdark, lab362)
78
- Bug #237: Fix redirect from LinkedIn if user refused to authorize permissions request (jakim)
89

910

src/AuthAction.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
use yii\base\Exception;
1212
use yii\base\InvalidConfigException;
1313
use yii\base\NotSupportedException;
14+
use yii\di\Instance;
1415
use yii\helpers\Url;
1516
use yii\web\Response;
1617
use yii\web\HttpException;
1718
use yii\web\NotFoundHttpException;
1819
use Yii;
20+
use yii\web\User;
1921

2022
/**
2123
* AuthAction performs authentication via different auth clients.
@@ -109,6 +111,12 @@ class AuthAction extends Action
109111
*/
110112
public $redirectView;
111113

114+
/**
115+
* @var User|array|string the User object or the application component ID of the user component.
116+
* @since 2.1.8
117+
*/
118+
public $user = 'user';
119+
112120
/**
113121
* @var string the redirect url after successful authorization.
114122
*/
@@ -118,6 +126,14 @@ class AuthAction extends Action
118126
*/
119127
private $_cancelUrl;
120128

129+
/**
130+
* @inheritdoc
131+
*/
132+
public function init()
133+
{
134+
parent::init();
135+
$this->user = Instance::ensure($this->user, User::className());
136+
}
121137

122138
/**
123139
* @param string $url successful URL.
@@ -165,7 +181,7 @@ public function getCancelUrl()
165181
*/
166182
protected function defaultSuccessUrl()
167183
{
168-
return Yii::$app->getUser()->getReturnUrl();
184+
return $this->user->getReturnUrl();
169185
}
170186

171187
/**
@@ -174,7 +190,7 @@ protected function defaultSuccessUrl()
174190
*/
175191
protected function defaultCancelUrl()
176192
{
177-
return Url::to(Yii::$app->getUser()->loginUrl);
193+
return Url::to($this->user->loginUrl);
178194
}
179195

180196
/**

0 commit comments

Comments
 (0)