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

ClaimsParameterChecker::check()   A

Complexity

Conditions 4
Paths 7

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 10
nc 7
nop 1
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