Failed Conditions
Push — master ( bb342a...37d2ca )
by Florent
04:25
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
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 1
b 0
f 0

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\AuthorizationEndpoint\ParameterChecker;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\Authorization;
17
use OAuth2Framework\Component\AuthorizationEndpoint\Exception\OAuth2AuthorizationException;
18
use OAuth2Framework\Component\Core\Message\OAuth2Message;
19
20
final class ClaimsParameterChecker implements ParameterChecker
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function check(Authorization $authorization): Authorization
26
    {
27
        try {
28
            if ($authorization->hasQueryParam('claims')) {
29
                $decoded = json_decode($authorization->getQueryParam('claims'), true);
30
                if (!is_array($decoded)) {
31
                    throw new \InvalidArgumentException('Invalid "claims" parameter.');
32
                }
33
34
                return $authorization->withClaims($decoded);
35
            }
36
37
            return $authorization;
38
        } catch (\InvalidArgumentException $e) {
39
            throw new OAuth2AuthorizationException(400, OAuth2Message::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e);
40
        }
41
    }
42
}
43