Passed
Push — master ( a721e7...5904cd )
by Rutger
13:40
created

Oauth2AuthorizeEndSessionAction::run()   A

Complexity

Conditions 6
Paths 12

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7.8984

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 27
ccs 10
cts 16
cp 0.625
rs 9.1111
cc 6
nc 12
nop 1
crap 7.8984
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())
0 ignored issues
show
Bug introduced by
It seems like Yii::app->request->post() can also be of type object; however, parameter $data of rhertogh\Yii2Oauth2Serve...equestInterface::load() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
                $endSessionAuthorizationRequest->load(/** @scrutinizer ignore-type */ Yii::$app->request->post())
Loading history...
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