Completed
Pull Request — master (#738)
by
unknown
62:12
created

OAuthClientOwnerMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of OAuth 2.0 Laravel.
5
 *
6
 * (c) Luca Degasperi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LucaDegasperi\OAuth2Server\Middleware;
13
14
use Closure;
15
use League\OAuth2\Server\Exception\AccessDeniedException;
16
use LucaDegasperi\OAuth2Server\Authorizer;
17
18
/**
19
 * This is the oauth client middleware class.
20
 *
21
 * @author Vincent Klaiber <[email protected]>
22
 */
23 View Code Duplication
class OAuthClientOwnerMiddleware
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    /**
26
     * The Authorizer instance.
27
     *
28
     * @var \LucaDegasperi\OAuth2Server\Authorizer
29
     */
30
    protected $authorizer;
31
32
    /**
33
     * Create a new oauth client middleware instance.
34
     *
35
     * @param \LucaDegasperi\OAuth2Server\Authorizer $authorizer
36
     */
37
    public function __construct(Authorizer $authorizer)
38
    {
39
        $this->authorizer = $authorizer;
40
    }
41
42
    /**
43
     * Handle an incoming request.
44
     *
45
     * @param \Illuminate\Http\Request $request
46
     * @param \Closure $next
47
     *
48
     * @throws \League\OAuth2\Server\Exception\AccessDeniedException
49
     *
50
     * @return mixed
51
     */
52
    public function handle($request, Closure $next)
53
    {
54
        $this->authorizer->setRequest($request);
55
56
        if ($this->authorizer->getResourceOwnerType() !== 'client') {
57
            throw new AccessDeniedException();
58
        }
59
60
        return $next($request);
61
    }
62
}
63