|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
//---------------------------------------------------------------------- |
|
4
|
|
|
// |
|
5
|
|
|
// Copyright (C) 2018 Artem Rodygin |
|
6
|
|
|
// |
|
7
|
|
|
// You should have received a copy of the MIT License along with |
|
8
|
|
|
// this file. If not, see <http://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
//---------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\OAuth2\Client\Provider; |
|
13
|
|
|
|
|
14
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
|
15
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
|
16
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
|
17
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
|
18
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Linode OAuth provider. |
|
22
|
|
|
*/ |
|
23
|
|
|
class Linode extends AbstractProvider |
|
24
|
|
|
{ |
|
25
|
|
|
use BearerAuthorizationTrait; |
|
26
|
|
|
|
|
27
|
|
|
// Available scopes. |
|
28
|
|
|
const SCOPE_ACCOUNT_READ_ONLY = 'account:read_only'; |
|
29
|
|
|
const SCOPE_ACCOUNT_READ_WRITE = 'account:read_write'; |
|
30
|
|
|
const SCOPE_DOMAINS_READ_ONLY = 'domains:read_only'; |
|
31
|
|
|
const SCOPE_DOMAINS_READ_WRITE = 'domains:read_write'; |
|
32
|
|
|
const SCOPE_EVENTS_READ_ONLY = 'events:read_only'; |
|
33
|
|
|
const SCOPE_EVENTS_READ_WRITE = 'events:read_write'; |
|
34
|
|
|
const SCOPE_IMAGES_READ_ONLY = 'images:read_only'; |
|
35
|
|
|
const SCOPE_IMAGES_READ_WRITE = 'images:read_write'; |
|
36
|
|
|
const SCOPE_IPS_READ_ONLY = 'ips:read_only'; |
|
37
|
|
|
const SCOPE_IPS_READ_WRITE = 'ips:read_write'; |
|
38
|
|
|
const SCOPE_LINODES_READ_ONLY = 'linodes:read_only'; |
|
39
|
|
|
const SCOPE_LINODES_READ_WRITE = 'linodes:read_write'; |
|
40
|
|
|
const SCOPE_LONGVIEW_READ_ONLY = 'longview:read_only'; |
|
41
|
|
|
const SCOPE_LONGVIEW_READ_WRITE = 'longview:read_write'; |
|
42
|
|
|
const SCOPE_NODEBALANCERS_READ_ONLY = 'nodebalancers:read_only'; |
|
43
|
|
|
const SCOPE_NODEBALANCERS_READ_WRITE = 'nodebalancers:read_write'; |
|
44
|
|
|
const SCOPE_STACKSCRIPTS_READ_ONLY = 'stackscripts:read_only'; |
|
45
|
|
|
const SCOPE_STACKSCRIPTS_READ_WRITE = 'stackscripts:read_write'; |
|
46
|
|
|
const SCOPE_VOLUMES_READ_ONLY = 'volumes:read_only'; |
|
47
|
|
|
const SCOPE_VOLUMES_READ_WRITE = 'volumes:read_write'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function getBaseAuthorizationUrl() |
|
53
|
|
|
{ |
|
54
|
1 |
|
return 'https://login.linode.com/oauth/authorize'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function getBaseAccessTokenUrl(array $params) |
|
61
|
|
|
{ |
|
62
|
1 |
|
return 'https://login.linode.com/oauth/token'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
69
|
|
|
{ |
|
70
|
1 |
|
return 'https://api.linode.com/v4/account'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
1 |
|
protected function getDefaultScopes() |
|
77
|
|
|
{ |
|
78
|
1 |
|
return []; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* {@inheritdoc} |
|
83
|
|
|
*/ |
|
84
|
2 |
|
protected function checkResponse(ResponseInterface $response, $data) |
|
85
|
|
|
{ |
|
86
|
2 |
|
if ($response->getStatusCode() >= 400) { |
|
87
|
1 |
|
$errors = isset($data['errors']) ? $data['errors'] : [['reason' => 'Unknown error']]; |
|
88
|
1 |
|
throw new IdentityProviderException($errors[0]['reason'], $response->getStatusCode(), $data); |
|
89
|
|
|
} |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
1 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
|
96
|
|
|
{ |
|
97
|
1 |
|
return new LinodeResourceOwner($response); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|