1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Alexandre |
5
|
|
|
* Date: 10/03/2018 |
6
|
|
|
* Time: 17:40 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OAuth2\Extensions\OpenID\Flows; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use OAuth2\Credentials\AuthorizationCodeInterface; |
13
|
|
|
use OAuth2\Endpoints\AuthorizationEndpoint; |
14
|
|
|
use OAuth2\Exceptions\OAuthException; |
15
|
|
|
use OAuth2\ResponseTypes\ResponseTypeInterface; |
16
|
|
|
use OAuth2\Storages\AuthorizationCodeStorageInterface; |
17
|
|
|
|
18
|
|
|
class AuthorizationCodeFlow extends \OAuth2\Flows\AuthorizationCodeFlow |
19
|
|
|
{ |
20
|
|
|
public function __construct(AuthorizationCodeStorageInterface $authorizationCodeStorage) |
21
|
|
|
{ |
22
|
|
|
parent::__construct($authorizationCodeStorage); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param AuthorizationEndpoint $authorizationEndpoint |
27
|
|
|
* @param array $requestData |
28
|
|
|
* @return array |
29
|
|
|
* @throws OAuthException |
30
|
|
|
*/ |
31
|
|
|
function handleAuthorizationRequest(AuthorizationEndpoint $authorizationEndpoint, array $requestData): array |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$authorizationCode = $this->createAuthorizationCode($authorizationEndpoint); |
34
|
|
|
if (in_array('openid', $authorizationEndpoint->getScopes())) { |
35
|
|
|
if (empty($requestData['redirect_uri'])) { |
36
|
|
|
throw new OAuthException('invalid_request', 'The request is missing the required parameter redirect_uri.', |
37
|
|
|
'https://tools.ietf.org/html/rfc6749#section-4.1'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
$requestData['nonce']; |
42
|
|
|
} |
43
|
|
|
return $this->saveAndGetResult($authorizationCode); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function createAuthorizationCode(AuthorizationEndpoint $authorizationEndpoint) |
47
|
|
|
{ |
48
|
|
|
return $this->authorizationCodeStorage->create( |
49
|
|
|
implode(' ', $authorizationEndpoint->getScopes()), |
50
|
|
|
$authorizationEndpoint->getClient()->getIdentifier(), |
51
|
|
|
$authorizationEndpoint->getResourceOwner()->getIdentifier(), |
52
|
|
|
$requestData['scope'] ?? null, |
|
|
|
|
53
|
|
|
$requestData['redirect_uri'] ?? null |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function saveAndGetResult(AuthorizationCodeInterface $authorizationCode) |
58
|
|
|
{ |
59
|
|
|
$this->authorizationCodeStorage->save($authorizationCode); |
60
|
|
|
return ['code' => $authorizationCode->getCode()]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.