Passport::getAuthorizationMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yeelight\Http\Controllers\Api\Auth\Provider;
4
5
use Dingo\Api\Auth\Provider\Authorization;
6
use Dingo\Api\Routing\Route;
7
use Illuminate\Auth\AuthManager;
8
use Illuminate\Http\Request;
9
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
10
11
/**
12
 * Class Passport
13
 *
14
 * @category Yeelight
15
 *
16
 * @package Yeelight\Http\Controllers\Api\Auth\Provider
17
 *
18
 * @author Sheldon Lee <[email protected]>
19
 *
20
 * @license https://opensource.org/licenses/MIT MIT
21
 *
22
 * @link https://www.yeelight.com
23
 */
24
class Passport extends Authorization
25
{
26
    /**
27
     * Illuminate authentication manager.
28
     *
29
     * @var \Illuminate\Contracts\Auth\Guard
30
     */
31
    protected $auth;
32
33
    /**
34
     * The guard driver name.
35
     *
36
     * @var string
37
     */
38
    protected $guard = 'api';
39
40
    /**
41
     * Create a new basic provider instance.
42
     *
43
     * @param \Illuminate\Auth\AuthManager $auth AuthManager
44
     */
45
    public function __construct(AuthManager $auth)
46
    {
47
        $this->auth = $auth->guard($this->guard);
48
    }
49
50
    /**
51
     * Authenticate request with a Illuminate Guard.
52
     *
53
     * @param \Illuminate\Http\Request $request Request
54
     * @param \Dingo\Api\Routing\Route $route Route
55
     *
56
     * @return mixed
57
     */
58
    public function authenticate(Request $request, Route $route)
59
    {
60
        if (!$user = $this->auth->user()) {
61
            throw new UnauthorizedHttpException(null, 'Unauthenticated.');
62
        }
63
64
        return $user;
65
    }
66
67
    /**
68
     * Get the providers authorization method.
69
     *
70
     * @return string
71
     */
72
    public function getAuthorizationMethod()
73
    {
74
        return 'Bearer';
75
    }
76
}
77