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

CheckClientCredentials::validateCredentials()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 CheckClientCredentials 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
                throw new MissingScopeException($scope);
43
            }
44
        }
45
    }
46
}
47