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