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

ClaimsParameterChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
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 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 17 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
final class ClaimsParameterChecker implements ParameterChecker
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function check(Authorization $authorization): Authorization
27
    {
28
        try {
29
            if ($authorization->hasQueryParam('claims')) {
30
                $decoded = json_decode($authorization->getQueryParam('claims'), true);
31
                if (!is_array($decoded)) {
32
                    throw new \InvalidArgumentException('Invalid "claims" parameter.');
33
                }
34
35
                return $authorization->withClaims($decoded);
36
            }
37
38
            return $authorization;
39
        } catch (\InvalidArgumentException $e) {
40
            throw new OAuth2AuthorizationException(400, OAuth2Message::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e);
41
        }
42
    }
43
}
44