|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the BEAR.JwtAuthModule package. |
|
5
|
|
|
* |
|
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace BEAR\JwtAuth; |
|
9
|
|
|
|
|
10
|
|
|
use BEAR\JwtAuth\Annotation\Cookie; |
|
11
|
|
|
use BEAR\JwtAuth\Annotation\Header; |
|
12
|
|
|
use BEAR\JwtAuth\Annotation\QueryParam; |
|
13
|
|
|
use BEAR\JwtAuth\Extractor\AuthorizationHeaderTokenExtractor; |
|
14
|
|
|
use BEAR\JwtAuth\Extractor\CookieTokenExtractor; |
|
15
|
|
|
use BEAR\JwtAuth\Extractor\QueryParameterTokenExtractor; |
|
16
|
|
|
use BEAR\JwtAuth\Extractor\TokenExtractorInterface; |
|
17
|
|
|
use Ray\AuraWebModule\AuraWebModule; |
|
18
|
|
|
use Ray\Di\AbstractModule; |
|
19
|
|
|
use Ray\Di\Scope; |
|
20
|
|
|
|
|
21
|
|
|
class TokenExtractorModule extends AbstractModule |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Used to detect token in header. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
private $header = ['Authorization', '/Bearer\s+(.*)$/i']; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Used to detect token in cookie. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $cookie = 'token'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Used to detect token in query string. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private $queryParam = 'token'; |
|
43
|
|
|
|
|
44
|
17 |
|
protected function configure() |
|
45
|
|
|
{ |
|
46
|
17 |
|
$this->install(new AuraWebModule()); |
|
47
|
|
|
|
|
48
|
17 |
|
$this->bind()->annotatedWith(Header::class)->toInstance($this->header); |
|
49
|
17 |
|
$this->bind()->annotatedWith(Cookie::class)->toInstance($this->cookie); |
|
50
|
17 |
|
$this->bind()->annotatedWith(QueryParam::class)->toInstance($this->queryParam); |
|
51
|
|
|
|
|
52
|
17 |
|
$this->bind(TokenExtractorInterface::class)->to(AuthorizationHeaderTokenExtractor::class)->in(Scope::SINGLETON); |
|
53
|
17 |
|
$this->bind(TokenExtractorInterface::class)->annotatedWith('query')->to(QueryParameterTokenExtractor::class)->in(Scope::SINGLETON); |
|
54
|
17 |
|
$this->bind(TokenExtractorInterface::class)->annotatedWith('cookie')->to(CookieTokenExtractor::class)->in(Scope::SINGLETON); |
|
55
|
17 |
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|