-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathClients.php
201 lines (165 loc) · 6.27 KB
/
Clients.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
declare(strict_types=1);
namespace Auth0\SDK\API\Management;
use Auth0\SDK\Contract\API\Management\ClientsInterface;
use Auth0\SDK\Utility\Request\RequestOptions;
use Auth0\SDK\Utility\Toolkit;
use Psr\Http\Message\ResponseInterface;
use function array_key_exists;
use function is_array;
/**
* Handles requests to the Clients endpoint of the v2 Management API.
*
* @see https://auth0.com/docs/api/management/v2#!/Clients
*/
final class Clients extends ManagementEndpoint implements ClientsInterface
{
public function create(
string $name,
?array $body = null,
?RequestOptions $options = null,
): ResponseInterface {
[$name] = Toolkit::filter([$name])->string()->trim();
[$body] = Toolkit::filter([$body])->array()->trim();
Toolkit::assert([
[$name, \Auth0\SDK\Exception\ArgumentException::missing('name')],
])->isString();
/** @var array<mixed> $body */
return $this->getHttpClient()
->method('post')
->addPath(['clients'])
->withBody(
(object) Toolkit::merge([[
'name' => $name,
], $body]),
)
->withOptions($options)
->call();
}
public function createCredentials(
string $clientId,
array $body,
?RequestOptions $options = null,
): ResponseInterface {
[$clientId] = Toolkit::filter([$clientId])->string()->trim();
[$body] = Toolkit::filter([$body])->array()->trim();
Toolkit::assert([
[$clientId, \Auth0\SDK\Exception\ArgumentException::missing('clientId')],
])->isString();
/** @var array<mixed> $body */
return $this->getHttpClient()
->method('post')->addPath(['clients', $clientId, 'credentials'])
->withBody((object) $body)
->withOptions($options)
->call();
}
public function delete(
string $id,
?RequestOptions $options = null,
): ResponseInterface {
[$id] = Toolkit::filter([$id])->string()->trim();
Toolkit::assert([
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
])->isString();
return $this->getHttpClient()
->method('delete')->addPath(['clients', $id])
->withOptions($options)
->call();
}
public function deleteCredential(
string $clientId,
string $credentialId,
?RequestOptions $options = null,
): ResponseInterface {
[$clientId, $credentialId] = Toolkit::filter([$clientId, $credentialId])->string()->trim();
Toolkit::assert([
[$clientId, \Auth0\SDK\Exception\ArgumentException::missing('clientId')],
[$credentialId, \Auth0\SDK\Exception\ArgumentException::missing('credentialId')],
])->isString();
return $this->getHttpClient()
->method('delete')->addPath(['clients', $clientId, 'credentials', $credentialId])
->withOptions($options)
->call();
}
public function get(
string $id,
?RequestOptions $options = null,
): ResponseInterface {
[$id] = Toolkit::filter([$id])->string()->trim();
Toolkit::assert([
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
])->isString();
return $this->getHttpClient()
->method('get')->addPath(['clients', $id])
->withOptions($options)
->call();
}
public function getAll(
?array $parameters = null,
?RequestOptions $options = null,
): ResponseInterface {
[$parameters] = Toolkit::filter([$parameters])->array()->trim();
/** @var array<null|int|string> $parameters */
// If the 'q' parameter is provided, ensure it's correctly passed in the query
if (isset($parameters['q'])) {
[$parameters['q']] = Toolkit::filter([$parameters['q']])->string()->trim();
}
return $this->getHttpClient()
->method('get')
->addPath(['clients'])
->withParams($parameters)
->withOptions($options)
->call();
}
public function getCredential(
string $clientId,
string $credentialId,
?RequestOptions $options = null,
): ResponseInterface {
[$clientId, $credentialId] = Toolkit::filter([$clientId, $credentialId])->string()->trim();
Toolkit::assert([
[$clientId, \Auth0\SDK\Exception\ArgumentException::missing('clientId')],
[$credentialId, \Auth0\SDK\Exception\ArgumentException::missing('credentialId')],
])->isString();
return $this->getHttpClient()
->method('get')->addPath(['clients', $clientId, 'credentials', $credentialId])
->withOptions($options)
->call();
}
public function getCredentials(
string $clientId,
?array $parameters = null,
?RequestOptions $options = null,
): ResponseInterface {
[$clientId] = Toolkit::filter([$clientId])->string()->trim();
[$parameters] = Toolkit::filter([$parameters])->array()->trim();
Toolkit::assert([
[$clientId, \Auth0\SDK\Exception\ArgumentException::missing('clientId')],
])->isString();
/** @var array<null|int|string> $parameters */
return $this->getHttpClient()
->method('get')->addPath(['clients', $clientId, 'credentials'])
->withParams($parameters)
->withOptions($options)
->call();
}
public function update(
string $id,
?array $body = null,
?RequestOptions $options = null,
): ResponseInterface {
[$id] = Toolkit::filter([$id])->string()->trim();
[$body] = Toolkit::filter([$body])->array()->trim();
Toolkit::assert([
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
])->isString();
if (is_array($body) && array_key_exists('initiate_login_uri', $body) && null === $body['initiate_login_uri']) {
$body['initiate_login_uri'] = '';
}
return $this->getHttpClient()
->method('patch')->addPath(['clients', $id])
->withBody($body ?? [])
->withOptions($options)
->call();
}
}