|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\Server\AuthorizationEndpoint\ParameterChecker; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Server\AuthorizationEndpoint\Authorization; |
|
17
|
|
|
use OAuth2Framework\Component\Server\Core\Response\OAuth2Exception; |
|
18
|
|
|
|
|
19
|
|
|
final class PromptParameterChecker implements ParameterChecker |
|
20
|
|
|
{ |
|
21
|
|
|
public const PROMPT_NONE = 'none'; |
|
22
|
|
|
|
|
23
|
|
|
public const PROMPT_LOGIN = 'login'; |
|
24
|
|
|
|
|
25
|
|
|
public const PROMPT_CONSENT = 'consent'; |
|
26
|
|
|
|
|
27
|
|
|
public const PROMPT_SELECT_ACCOUNT = 'select_account'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function process(Authorization $authorization, callable $next): Authorization |
|
33
|
|
|
{ |
|
34
|
|
|
try { |
|
35
|
|
|
if ($authorization->hasQueryParam('prompt')) { |
|
36
|
|
|
$prompt = $authorization->getPrompt(); |
|
37
|
|
|
$diff = array_diff($prompt, $this->getAllowedPromptValues()); |
|
38
|
|
|
if (!empty($diff)) { |
|
39
|
|
|
throw new \InvalidArgumentException(sprintf('Invalid parameter "prompt". Allowed values are %s', implode(', ', $this->getAllowedPromptValues()))); |
|
40
|
|
|
} |
|
41
|
|
|
if (in_array('none', $prompt) && 1 !== count($prompt)) { |
|
42
|
|
|
throw new \InvalidArgumentException('Invalid parameter "prompt". Prompt value "none" must be used alone.'); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $next($authorization); |
|
47
|
|
|
} catch (\InvalidArgumentException $e) { |
|
48
|
|
|
throw new OAuth2Exception(400, OAuth2Exception::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return string[] |
|
54
|
|
|
*/ |
|
55
|
|
|
private function getAllowedPromptValues(): array |
|
56
|
|
|
{ |
|
57
|
|
|
return [ |
|
58
|
|
|
self::PROMPT_NONE, |
|
59
|
|
|
self::PROMPT_LOGIN, |
|
60
|
|
|
self::PROMPT_CONSENT, |
|
61
|
|
|
self::PROMPT_SELECT_ACCOUNT, |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: