Completed
Push — master ( b97427...e235cc )
by Raffael
30:35 queued 26:08
created

Token   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 63
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A authenticate() 0 19 3
A getAttributes() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Wopi\Auth;
13
14
use Balloon\App\Wopi\SessionManager;
15
use Micro\Auth\Adapter\AbstractAdapter;
16
use Micro\Auth\Auth;
17
18
class Token extends AbstractAdapter
19
{
20
    /**
21
     * Attributes.
22
     *
23
     * @var array
24
     */
25
    protected $attributes = [];
26
27
    /**
28
     * Auth.
29
     *
30
     * @var Auth
31
     */
32
    protected $auth;
33
34
    /**
35
     * Session manager.
36
     *
37
     * @var SessionManager
38
     */
39
    protected $manager;
40
41
    /**
42
     * Set options.
43
     */
44
    public function __construct(SessionManager $manager, Auth $auth)
45
    {
46
        $this->manager = $manager;
47
        $this->auth = $auth;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function authenticate(): bool
54
    {
55
        if (preg_match('#^/index.php/api/v2/office/wopi/files/#', $_SERVER['ORIG_SCRIPT_NAME']) === false) {
56
            return false;
57
        }
58
59
        $token = $_GET['access_token'] ?? null;
60
61
        if ($token === null) {
62
            return false;
63
        }
64
65
        $user = $this->manager->authenticate($token);
66
67
        $this->identifier = $user->getUsername();
68
        $this->attributes = $user->getAttributes();
69
70
        return true;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getAttributes(): array
77
    {
78
        return $this->attributes;
79
    }
80
}
81