1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\components\authorization\EndSession; |
4
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\components\authorization\base\Oauth2BaseAuthorizationRequest; |
6
|
|
|
use rhertogh\Yii2Oauth2Server\components\authorization\EndSession\base\Oauth2BaseEndSessionAuthorizationRequest; |
7
|
|
|
use rhertogh\Yii2Oauth2Server\helpers\UrlHelper; |
8
|
|
|
use Yii; |
9
|
|
|
use yii\base\InvalidCallException; |
10
|
|
|
|
11
|
|
|
class Oauth2EndSessionAuthorizationRequest extends Oauth2BaseEndSessionAuthorizationRequest |
12
|
|
|
{ |
13
|
|
|
public function isAuthorizationAllowed() |
14
|
|
|
{ |
15
|
|
|
return $this->getModule()->getUserIdentity() !== null; |
|
|
|
|
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function processAuthorization() |
19
|
|
|
{ |
20
|
|
|
if ($this->isApproved()) { |
21
|
|
|
$this->getModule()->logoutUser(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$this->setCompleted(true); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
*/ |
30
|
|
|
public function getEndSessionRequestUrl() |
31
|
|
|
{ |
32
|
|
|
return UrlHelper::addQueryParams( |
33
|
|
|
$this->getEndSessionUrl(), |
34
|
|
|
[ |
35
|
|
|
'endSessionAuthorizationRequestId' => $this->getRequestId() |
36
|
|
|
] |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function autoApproveAndProcess() |
41
|
|
|
{ |
42
|
|
|
if ($this->getEndUserAuthorizationRequired()) { |
43
|
|
|
throw new InvalidCallException('Auto approve is only allowed if end-user authorization is not required.'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->setAuthorizationStatus(Oauth2BaseAuthorizationRequest::AUTHORIZATION_APPROVED); |
47
|
|
|
$this->processAuthorization(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getRequestCompletedRedirectUrl($ignoreApprovalStatus = false) |
51
|
|
|
{ |
52
|
|
|
if (!$this->isApproved()) { |
53
|
|
|
return $this->getDeniedRedirectUrl(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$redirectUri = $this->getRedirectUri(); |
57
|
|
|
|
58
|
|
|
if (!$redirectUri) { |
59
|
|
|
return $this->getDefaultRedirectUrl(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// Return the original `post_logout_redirect_uri` with the `state` |
|
|
|
|
63
|
|
|
return UrlHelper::addQueryParams($redirectUri, ['state' => $this->getState()]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function getDefaultRedirectUrl() |
67
|
|
|
{ |
68
|
|
|
return Yii::$app->getHomeUrl(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getDeniedRedirectUrl() |
72
|
|
|
{ |
73
|
|
|
return Yii::$app->getHomeUrl(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.