ErrorScopePolicy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getScopes() 0 8 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: GCC-MED
5
 * Date: 15/01/2018
6
 * Time: 10:20
7
 */
8
9
namespace OAuth2\ScopePolicy\Policies;
10
11
12
use OAuth2\Exceptions\OAuthException;
13
use OAuth2\Roles\ClientInterface;
14
15
/**
16
 * Class ErrorScopePolicy
17
 * @package OAuth2\ScopePolicy\Policies
18
 *
19
 * @see https://tools.ietf.org/html/rfc6749#section-3.3
20
 * If the client omits the scope parameter when requesting
21
 * authorization, the authorization server MUST either process the
22
 * request using a pre-defined default value or fail the request
23
 * indicating an invalid scope.
24
 */
25
class ErrorScopePolicy implements ScopePolicyInterface
26
{
27
    /**
28
     * @param ClientInterface $client
29
     * @param array|null $scopes
30
     * @return array|null
31
     * @throws OAuthException
32
     */
33
    public function getScopes(ClientInterface $client, ?array $scopes): array
34
    {
35
        if (empty($scopes)) {
36
            throw new OAuthException('invalid_scope',
37
                'The request is missing the required parameter scope.',
38
                'https://tools.ietf.org/html/rfc6749#section-4.1');
39
        }
40
        return $scopes;
41
    }
42
}