Failed Conditions
Push — master ( 37d2ca...f68d8f )
by Florent
05:43 queued 01:15
created

NonceParameterChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 12 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\OpenIdConnect\ParameterChecker;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\Authorization;
17
use OAuth2Framework\Component\AuthorizationEndpoint\Exception\OAuth2AuthorizationException;
18
use OAuth2Framework\Component\AuthorizationEndpoint\ParameterChecker\ParameterChecker;
19
use OAuth2Framework\Component\Core\Message\OAuth2Message;
20
21
/**
22
 * Class NonceParameterChecker.
23
 */
24
final class NonceParameterChecker implements ParameterChecker
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function check(Authorization $authorization): Authorization
30
    {
31
        try {
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 OAuth2AuthorizationException(400, OAuth2Message::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e);
39
        }
40
    }
41
}
42