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

Token::authenticate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 14
cp 0
rs 9.6333
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 12
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