Passed
Pull Request — 1.11.x (#5763)
by Angel Fernando Quiroz
08:52
created

AzureCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/* For license terms, see /license.txt */
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use League\OAuth2\Client\Token\AccessTokenInterface;
7
use TheNetworg\OAuth2\Client\Provider\Azure;
8
9
class AzureCommand
10
{
11
    /**
12
     * @var AzureActiveDirectory
13
     */
14
    protected $plugin;
15
    /**
16
     * @var Azure
17
     */
18
    protected $provider;
19
20
    public function __construct()
21
    {
22
        $this->plugin = AzureActiveDirectory::create();
23
        $this->plugin->get_settings(true);
24
        $this->provider = $this->plugin->getProviderForApiGraph();
25
    }
26
27
    /**
28
     * @throws IdentityProviderException
29
     */
30
    protected function getToken(?AccessTokenInterface $currentToken = null): AccessTokenInterface
31
    {
32
        if (!$currentToken || ($currentToken->getExpires() && !$currentToken->getRefreshToken())) {
33
            return $this->provider->getAccessToken(
34
                'client_credentials',
35
                ['resource' => $this->provider->resource]
36
            );
37
        }
38
39
        return $currentToken;
40
    }
41
}
42