Completed
Push — master ( 794ec6...01bc45 )
by Andrew
06:50
created

OAuth::getToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 4
crap 1
1
<?php
2
3
namespace NodeRED;
4
5
class OAuth
6
{
7
    private $instance;
8
9
    const CLIENT_NODE_RED_ADMIN = 'node-red-admin';
10
    const CLIENT_NODE_RED_EDITOR = 'node-red-editor';
11
12
    const SCOPE_ALL = '*';
13
    const SCOPE_READ = 'read';
14
15 1
    public function __construct(Instance $instance)
16
    {
17 1
        $this->instance = $instance;
18 1
    }
19
20 1
    public function getToken($username, $password, $clientId = self::CLIENT_NODE_RED_ADMIN, $scope = self::SCOPE_ALL)
21
    {
22 1
        $data = $this->instance->formPost('auth/token', [
23 1
            'grant_type' => 'password',
24 1
            'username' => $username,
25 1
            'password' => $password,
26 1
            'client_id' => $clientId,
27
            'scope' => $scope
28 1
        ]);
29
30 1
        return new OAuthToken($data['access_token'], $data['expires_in'], $data['token_type']);
31
    }
32
}
33