Completed
Branch master (31a531)
by
unknown
02:59
created

TokenExtractorModule   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 36
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
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 16
    protected function configure()
45
    {
46 16
        $this->install(new AuraWebModule());
47
48 16
        $this->bind()->annotatedWith(Header::class)->toInstance($this->header);
49 16
        $this->bind()->annotatedWith(Cookie::class)->toInstance($this->cookie);
50 16
        $this->bind()->annotatedWith(QueryParam::class)->toInstance($this->queryParam);
51
52 16
        $this->bind(TokenExtractorInterface::class)->to(AuthorizationHeaderTokenExtractor::class)->in(Scope::SINGLETON);
53 16
        $this->bind(TokenExtractorInterface::class)->annotatedWith('query')->to(QueryParameterTokenExtractor::class)->in(Scope::SINGLETON);
54 16
        $this->bind(TokenExtractorInterface::class)->annotatedWith('cookie')->to(CookieTokenExtractor::class)->in(Scope::SINGLETON);
55 16
    }
56
}
57