1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
4
|
|
|
// |
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
6
|
|
|
// |
7
|
|
|
// You should have received a copy of the MIT License along with |
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
9
|
|
|
// |
10
|
|
|
// --------------------------------------------------------------------- |
11
|
|
|
|
12
|
|
|
namespace Linode\Account\Repository; |
13
|
|
|
|
14
|
|
|
use Linode\Account\OAuthClient; |
15
|
|
|
use Linode\Account\OAuthClientRepositoryInterface; |
16
|
|
|
use Linode\Entity; |
17
|
|
|
use Linode\Internal\AbstractRepository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
21
|
|
|
*/ |
22
|
|
|
class OAuthClientRepository extends AbstractRepository implements OAuthClientRepositoryInterface |
23
|
|
|
{ |
24
|
|
|
public function createClient(array $parameters = []): OAuthClient |
25
|
|
|
{ |
26
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
27
|
|
|
$contents = $response->getBody()->getContents(); |
28
|
|
|
$json = json_decode($contents, true); |
29
|
|
|
|
30
|
|
|
return new OAuthClient($this->client, $json); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function updateClient(string $clientId, array $parameters = []): OAuthClient |
34
|
|
|
{ |
35
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $clientId), $parameters); |
36
|
|
|
$contents = $response->getBody()->getContents(); |
37
|
|
|
$json = json_decode($contents, true); |
38
|
|
|
|
39
|
|
|
return new OAuthClient($this->client, $json); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function deleteClient(string $clientId): void |
43
|
|
|
{ |
44
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $clientId)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function resetClientSecret(string $clientId): OAuthClient |
48
|
|
|
{ |
49
|
|
|
$response = $this->client->post(sprintf('%s/%s/reset-secret', $this->getBaseUri(), $clientId)); |
50
|
|
|
$contents = $response->getBody()->getContents(); |
51
|
|
|
$json = json_decode($contents, true); |
52
|
|
|
|
53
|
|
|
return new OAuthClient($this->client, $json); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getClientThumbnail(string $clientId): string |
57
|
|
|
{ |
58
|
|
|
$response = $this->client->get(sprintf('%s/%s/thumbnail', $this->getBaseUri(), $clientId)); |
59
|
|
|
|
60
|
|
|
return $response->getBody()->getContents(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setClientThumbnail(string $clientId, string $file): void |
64
|
|
|
{ |
65
|
|
|
$options = [ |
66
|
|
|
'body' => fopen($file, 'r'), |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
$this->client->put(sprintf('%s/%s/thumbnail', $this->getBaseUri(), $clientId), [], $options); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function getBaseUri(): string |
73
|
|
|
{ |
74
|
|
|
return '/account/oauth-clients'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function getSupportedFields(): array |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
OAuthClient::FIELD_ID, |
81
|
|
|
OAuthClient::FIELD_LABEL, |
82
|
|
|
OAuthClient::FIELD_STATUS, |
83
|
|
|
OAuthClient::FIELD_PUBLIC, |
84
|
|
|
OAuthClient::FIELD_REDIRECT_URI, |
85
|
|
|
OAuthClient::FIELD_SECRET, |
86
|
|
|
OAuthClient::FIELD_THUMBNAIL_URL, |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function jsonToEntity(array $json): Entity |
91
|
|
|
{ |
92
|
|
|
return new OAuthClient($this->client, $json); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|