Failed Conditions
Push — ng ( ada769...ebc492 )
by Florent
08:29 queued 40s
created

NonceParameterChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 13 4
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\OpenIdConnect;
15
16
use OAuth2Framework\Component\Server\AuthorizationEndpoint\Authorization;
17
use OAuth2Framework\Component\Server\AuthorizationEndpoint\ParameterChecker\ParameterChecker;
18
use OAuth2Framework\Component\Server\Core\Response\OAuth2Exception;
19
20
/**
21
 * Class NonceParameterChecker.
22
 */
23
final class NonceParameterChecker implements ParameterChecker
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function process(Authorization $authorization, callable $next): Authorization
29
    {
30
        try {
31
            $authorization = $next($authorization);
32
            if (false !== strpos($authorization->getQueryParam('response_type'), 'id_token') && !$authorization->hasQueryParam('nonce')) {
33
                throw new \InvalidArgumentException('The parameter "nonce" is mandatory when the response type "id_token" is used.');
34
            }
35
36
            return $authorization;
37
        } catch (\InvalidArgumentException $e) {
38
            throw new OAuth2Exception(400, OAuth2Exception::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e);
39
        }
40
    }
41
}
42