NonceParameterChecker::check()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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\OpenIdConnect\ParameterChecker;
15
16
use InvalidArgumentException;
17
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
18
use OAuth2Framework\Component\AuthorizationEndpoint\ParameterChecker\ParameterChecker;
19
20
final class NonceParameterChecker implements ParameterChecker
21
{
22
    public function check(AuthorizationRequest $authorization): void
23
    {
24
        if (!$authorization->hasQueryParam('response_type')) {
25
            throw new InvalidArgumentException('The parameter "response_type" is mandatory.');
26
        }
27
        $response_type = explode(' ', $authorization->getQueryParam('response_type'));
28
        if (\in_array('id_token', $response_type, true) && !$authorization->hasQueryParam('nonce')) {
29
            throw new InvalidArgumentException('The parameter "nonce" is mandatory when the response type "id_token" is used.');
30
        }
31
    }
32
}
33