1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Alexandre |
5
|
|
|
* Date: 14/03/2018 |
6
|
|
|
* Time: 22:13 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OAuth2\Extensions\OpenID\AuthorizationGrantTypes\Flows; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use OAuth2\Endpoints\Authorization\AuthorizationRequestInterface; |
13
|
|
|
use OAuth2\Endpoints\AuthorizationEndpoint; |
14
|
|
|
use OAuth2\Endpoints\TokenEndpoint; |
15
|
|
|
use OAuth2\Exceptions\OAuthException; |
16
|
|
|
use OAuth2\Extensions\OpenID\IdTokenManager; |
17
|
|
|
use OAuth2\Extensions\OpenID\Roles\Clients\ClientMetadataInterface; |
18
|
|
|
use OAuth2\AuthorizationGrantTypes\Flows\FlowInterface; |
19
|
|
|
use OAuth2\AuthorizationGrantTypes\AbstractGrantType; |
20
|
|
|
use OAuth2\Extensions\OpenID\Roles\ResourceOwnerInterface; |
|
|
|
|
21
|
|
|
use OAuth2\Helper; |
22
|
|
|
use OAuth2\Storages\AccessTokenStorageInterface; |
23
|
|
|
use OAuth2\Storages\RefreshTokenStorageInterface; |
24
|
|
|
|
25
|
|
|
class ImplicitFlow extends AbstractGrantType implements FlowInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var IdTokenManager |
29
|
|
|
*/ |
30
|
|
|
private $idTokenManager; |
31
|
|
|
|
32
|
|
|
public function __construct(AccessTokenStorageInterface $accessTokenStorage, |
33
|
|
|
RefreshTokenStorageInterface $refreshTokenStorage, |
34
|
|
|
IdTokenManager $idTokenManager) |
35
|
|
|
{ |
36
|
|
|
parent::__construct($accessTokenStorage, $refreshTokenStorage); |
37
|
|
|
$this->idTokenManager = $idTokenManager; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return string[] |
42
|
|
|
*/ |
43
|
|
|
public function getResponseTypes(): array |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
'id_token', |
47
|
|
|
'id_token token' |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string[] |
53
|
|
|
*/ |
54
|
|
|
public function getGrantTypes(): array |
55
|
|
|
{ |
56
|
|
|
return []; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function handleAccessTokenRequest(TokenEndpoint $tokenEndpoint, array $requestData): array |
60
|
|
|
{ |
61
|
|
|
return []; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param AuthorizationEndpoint $authorizationEndpoint |
66
|
|
|
* @param array $requestData |
67
|
|
|
* @throws OAuthException |
68
|
|
|
*/ |
69
|
|
|
public function verifyAuthorizationRequest(AuthorizationEndpoint $authorizationEndpoint, array $requestData) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
if (!$authorizationEndpoint instanceof \OAuth2\Extensions\OpenID\Endpoints\AuthorizationEndpoint) { |
72
|
|
|
throw new \InvalidArgumentException(); |
73
|
|
|
} |
74
|
|
|
if (!$authorizationEndpoint->getNonce()) { |
75
|
|
|
throw new OAuthException('invalid_request', 'Nonce required'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param AuthorizationEndpoint $authorizationEndpoint |
81
|
|
|
* @param array $requestData |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function handleAuthorizationRequest(AuthorizationRequestInterface $authorizationRequest): array |
85
|
|
|
{ |
86
|
|
|
if (!$authorizationEndpoint instanceof \OAuth2\Extensions\OpenID\Endpoints\AuthorizationEndpoint) { |
|
|
|
|
87
|
|
|
throw new \InvalidArgumentException(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$resourceOwner = $authorizationEndpoint->getResourceOwner(); |
|
|
|
|
91
|
|
|
$idToken = []; |
92
|
|
|
|
93
|
|
|
if ($resourceOwner instanceof ResourceOwnerInterface) { |
94
|
|
|
if (!is_null($authorizationEndpoint->getMaxAge())) { |
95
|
|
|
$time = $resourceOwner->getLastTimeActivelyAuthenticated(); |
96
|
|
|
$idToken['auth_time'] = $time ? $time->getTimestamp() : $authorizationEndpoint->getMaxAge(); |
97
|
|
|
} |
98
|
|
|
$acr = $resourceOwner->getAuthenticationContextClassReference(); |
99
|
|
|
if (!is_null($acr)) { |
100
|
|
|
$idToken['acr'] = $acr; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$amr = $resourceOwner->getAuthenticationMethodsReferences(); |
104
|
|
|
if (!is_null($amr)) { |
105
|
|
|
$idToken['amr'] = $amr; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if (!is_null($authorizationEndpoint->getNonce())) { |
110
|
|
|
$idToken['nonce'] = $authorizationEndpoint->getNonce(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$accessToken = $this->issueAccessToken( |
114
|
|
|
$authorizationEndpoint->getScopes(), |
|
|
|
|
115
|
|
|
$authorizationEndpoint->getClient()->getIdentifier(), |
|
|
|
|
116
|
|
|
$authorizationEndpoint->getResourceOwner()->getIdentifier() |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$alg = 'RS256'; |
120
|
|
|
$metadata = $authorizationEndpoint->getClient()->getMetadata(); |
121
|
|
|
if ($metadata instanceof ClientMetadataInterface) { |
122
|
|
|
$alg = $metadata->getIdTokenSignedResponseAlg() ?: 'RS256'; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$macAlgorithm = substr($alg, -3); |
126
|
|
|
|
127
|
|
|
if (!in_array($macAlgorithm, [256, 384, 512])) { |
128
|
|
|
throw new \UnexpectedValueException("Algotihmn '".$macAlgorithm."' not supported"); |
129
|
|
|
} |
130
|
|
|
$macAlgorithm = 'sha' . $macAlgorithm; |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
$atHash = hash($macAlgorithm, $accessToken['access_token'], true); |
134
|
|
|
$atHash = substr($atHash, 0, strlen($atHash) / 2); |
135
|
|
|
$atHash = Helper::base64url_encode($atHash); |
136
|
|
|
$idToken['at_hash'] = $atHash; |
137
|
|
|
|
138
|
|
|
$result = []; |
139
|
|
|
$result['id_token'] = $this->idTokenManager->issueIdToken( |
140
|
|
|
$authorizationEndpoint->getClient(), |
141
|
|
|
$authorizationEndpoint->getResourceOwner() |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
// $result = array_merge($result, $accessToken); |
|
|
|
|
145
|
|
|
return $result; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getDefaultResponseMode(): string |
149
|
|
|
{ |
150
|
|
|
return 'fragment'; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function getUnsupportedResponseModes(): array |
154
|
|
|
{ |
155
|
|
|
return ['query']; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function isRegistrationOfRedirectUriRequired(): bool |
159
|
|
|
{ |
160
|
|
|
return true; |
161
|
|
|
} |
162
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths