Repository navigation
Expand file tree
/
Copy pathBasic.php
More file actions
68 lines (59 loc) · 1.53 KB
/
Copy pathBasic.php
File metadata and controls
68 lines (59 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Dingo\Api\Auth\Provider;
use Illuminate\Http\Request;
use Dingo\Api\Routing\Route;
use Illuminate\Auth\AuthManager;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
class Basic extends Authorization
{
/**
* Illuminate authentication manager.
*
* @var \Illuminate\Auth\AuthManager
*/
protected $auth;
/**
* Basic auth identifier.
*
* @var string
*/
protected $identifier;
/**
* Create a new basic provider instance.
*
* @param \Illuminate\Auth\AuthManager $auth
* @param string $identifier
*
* @return void
*/
public function __construct(AuthManager $auth, $identifier = 'email')
{
$this->auth = $auth;
$this->identifier = $identifier;
}
/**
* Authenticate request with Basic.
*
* @param \Illuminate\Http\Request $request
* @param \Dingo\Api\Routing\Route $route
*
* @return mixed
*/
public function authenticate(Request $request, Route $route)
{
$this->validateAuthorizationHeader($request);
if (($response = $this->auth->onceBasic($this->identifier)) && $response->getStatusCode() === 401) {
throw new UnauthorizedHttpException('Basic', 'Invalid authentication credentials.');
}
return $this->auth->user();
}
/**
* Get the providers authorization method.
*
* @return string
*/
public function getAuthorizationMethod()
{
return 'basic';
}
}