Completed
Push — master ( 592d95...c00565 )
by Abdelrahman
18:11 queued 10s
created

CheckClientCredentialsForAnyScope   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateCredentials() 0 6 2
A validateScopes() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Oauth\Http\Middleware;
6
7
use Illuminate\Auth\AuthenticationException;
8
use Rinvex\Oauth\Exceptions\MissingScopeException;
9
10
class CheckClientCredentialsForAnyScope extends CheckCredentials
11
{
12
    /**
13
     * Validate token credentials.
14
     *
15
     * @param \Rinvex\Oauth\Models\AccessToken $accessToken
16
     *
17
     * @throws \Illuminate\Auth\AuthenticationException
18
     *
19
     * @return void
20
     */
21
    protected function validateCredentials($accessToken)
22
    {
23
        if (! $accessToken) {
24
            throw new AuthenticationException();
25
        }
26
    }
27
28
    /**
29
     * Validate token credentials.
30
     *
31
     * @param \Rinvex\Oauth\Models\AccessToken $accessToken
32
     * @param array                            $scopes
33
     *
34
     * @throws \Rinvex\Oauth\Exceptions\MissingScopeException
35
     *
36
     * @return void
37
     */
38
    protected function validateScopes($accessToken, $scopes)
39
    {
40
        foreach ($scopes as $scope) {
41
            if (! $accessToken->abilities->map->getRouteKey()->contains($scope)) {
42
                return;
43
            }
44
        }
45
46
        throw new MissingScopeException($scopes);
47
    }
48
}
49