1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\controllers\web\consent; |
4
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\controllers\web\base\Oauth2BaseWebAction; |
6
|
|
|
use rhertogh\Yii2Oauth2Server\controllers\web\Oauth2ConsentController; |
7
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\consent\Oauth2AuthorizeEndSessionActionInterface; |
8
|
|
|
use Yii; |
9
|
|
|
use yii\base\InvalidConfigException; |
10
|
|
|
use yii\web\BadRequestHttpException; |
11
|
|
|
use yii\web\HttpException; |
12
|
|
|
use yii\web\ServerErrorHttpException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @property Oauth2ConsentController $controller |
16
|
|
|
*/ |
17
|
|
|
class Oauth2AuthorizeEndSessionAction extends Oauth2BaseWebAction implements Oauth2AuthorizeEndSessionActionInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Path to view file for End Session authorization. |
21
|
|
|
* @var string|null |
22
|
|
|
*/ |
23
|
|
|
public $openIdConnectLogoutConfirmationView = null; |
24
|
|
|
|
25
|
1 |
|
public function init() |
26
|
|
|
{ |
27
|
1 |
|
parent::init(); |
28
|
1 |
|
if (empty($this->openIdConnectLogoutConfirmationView)) { |
29
|
|
|
throw new InvalidConfigException('$openIdConnectLogoutConfirmationView must be set.'); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
public function run($endSessionAuthorizationRequestId) |
34
|
|
|
{ |
35
|
|
|
try { |
36
|
1 |
|
$module = $this->controller->module; |
37
|
|
|
|
38
|
1 |
|
$endSessionAuthorizationRequest = $module->getEndSessionAuthReqSession($endSessionAuthorizationRequestId); |
39
|
|
|
|
40
|
1 |
|
if (empty($endSessionAuthorizationRequest)) { |
41
|
|
|
throw new BadRequestHttpException(Yii::t('oauth2', 'Invalid endSessionAuthorizationRequestId.')); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ( |
45
|
1 |
|
$endSessionAuthorizationRequest->load(Yii::$app->request->post()) |
|
|
|
|
46
|
1 |
|
&& $endSessionAuthorizationRequest->validate() |
47
|
|
|
) { |
48
|
1 |
|
return $module->generateEndSessionAuthReqCompledRedirectResponse($endSessionAuthorizationRequest); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
return $this->controller->render($this->openIdConnectLogoutConfirmationView, [ |
52
|
1 |
|
'endSessionAuthorizationRequest' => $endSessionAuthorizationRequest, |
53
|
1 |
|
]); |
54
|
|
|
} catch (\Exception $e) { |
55
|
|
|
$message = Yii::t('oauth2', 'Unable to respond to logout authorization request.'); |
56
|
|
|
if ($e instanceof HttpException) { |
57
|
|
|
$message .= ' ' . $e->getMessage(); |
58
|
|
|
} |
59
|
|
|
throw new ServerErrorHttpException($message, 0, $e); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|