forked from auth0/auth0-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientsEntity.java
More file actions
296 lines (269 loc) · 11.5 KB
/
ClientsEntity.java
File metadata and controls
296 lines (269 loc) · 11.5 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package com.auth0.client.mgmt;
import com.auth0.client.mgmt.filter.ClientFilter;
import com.auth0.client.mgmt.filter.FieldsFilter;
import com.auth0.json.mgmt.client.Client;
import com.auth0.json.mgmt.client.ClientsPage;
import com.auth0.json.mgmt.client.Credential;
import com.auth0.net.EmptyBodyRequest;
import com.auth0.net.BaseRequest;
import com.auth0.net.Request;
import com.auth0.net.VoidRequest;
import com.auth0.net.client.Auth0HttpClient;
import com.auth0.net.client.HttpMethod;
import com.auth0.utils.Asserts;
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import java.util.List;
import java.util.Map;
/**
* Class that provides an implementation of the Application methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Clients
* <p>
* This class is not thread-safe.
*
* @see ManagementAPI
*/
@SuppressWarnings("WeakerAccess")
public class ClientsEntity extends BaseManagementEntity {
ClientsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) {
super(client, baseUrl, tokenProvider);
}
/**
* Request all the Applications. A token with scope read:clients is needed. If you also need the client_secret and encryption_key attributes the token must have read:client_keys scope.
* See https://auth0.com/docs/api/management/v2#!/Clients/get_clients
*
* @param filter the filter to use. Can be null.
* @return a Request to execute.
*/
public Request<ClientsPage> list(ClientFilter filter) {
HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients");
if (filter != null) {
for (Map.Entry<String, Object> e : filter.getAsMap().entrySet()) {
builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue()));
}
}
String url = builder.build().toString();
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<ClientsPage>() {
});
}
/**
* Request an Application. A token with scope read:clients is needed. If you also need the client_secret and encryption_key attributes the token must have read:client_keys scope.
* See https://auth0.com/docs/api/management/v2#!/Clients/get_clients_by_id
*
* @param clientId the application's client id.
* @return a Request to execute.
*/
public Request<Client> get(String clientId) {
Asserts.assertNotNull(clientId, "client id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.build()
.toString();
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Client>() {
});
}
/**
* Request an Application. A token with scope read:clients is needed. If you also need the client_secret and encryption_key attributes the token must have read:client_keys scope.
* See https://auth0.com/docs/api/management/v2#!/Clients/get_clients_by_id
*
* @param clientId the application's client id.
* @param filter optional filter to restrict fields (to be included/excluded in response)
* @return a Request to execute.
*/
public Request<Client> get(String clientId, FieldsFilter filter) {
Asserts.assertNotNull(clientId, "client id");
HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId);
if (filter != null) {
for (Map.Entry<String, Object> e : filter.getAsMap().entrySet()) {
builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue()));
}
}
String url = builder.build().toString();
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Client>() {
});
}
/**
* Create a new Application. A token with scope create:clients is needed.
* See https://auth0.com/docs/api/management/v2#!/Clients/post_clients
*
* @param client the application data to set.
* @return a Request to execute.
*/
public Request<Client> create(Client client) {
Asserts.assertNotNull(client, "client");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.build()
.toString();
BaseRequest<Client> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Client>() {
});
request.setBody(client);
return request;
}
/**
* Delete an existing Application. A token with scope delete:clients is needed.
* See https://auth0.com/docs/api/management/v2#!/Clients/delete_clients_by_id
*
* @param clientId the application's client id.
* @return a Request to execute.
*/
public Request<Void> delete(String clientId) {
Asserts.assertNotNull(clientId, "client id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.build()
.toString();
return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE);
}
/**
* Update an existing Application. A token with scope update:clients is needed. If you also need to update the client_secret and encryption_key attributes the token must have update:client_keys scope.
* See https://auth0.com/docs/api/management/v2#!/Clients/patch_clients_by_id
*
* @param clientId the application's client id.
* @param client the application data to set.
* @return a Request to execute.
*/
public Request<Client> update(String clientId, Client client) {
Asserts.assertNotNull(clientId, "client id");
Asserts.assertNotNull(client, "client");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.build()
.toString();
BaseRequest<Client> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<Client>() {
});
request.setBody(client);
return request;
}
/**
* Rotates an Application's client secret. A token with scope update:client_keys is needed. Note that the generated secret is NOT base64 encoded.
* See https://auth0.com/docs/api/management/v2#!/Clients/post_rotate_secret
*
* @param clientId the application's client id.
* @return a Request to execute.
*/
public Request<Client> rotateSecret(String clientId) {
Asserts.assertNotNull(clientId, "client id");
Asserts.assertNotNull(client, "client");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.addPathSegment("rotate-secret")
.build()
.toString();
return new EmptyBodyRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Client>() {
});
}
/**
* Creates an Application's client credential. A token with scope {@code create:client_credentials} is required.
*
* @param clientId the application's client id.
* @param credential the credential to create.
* @return a Request to execute.
*/
public Request<Credential> createCredential(String clientId, Credential credential) {
Asserts.assertNotNull(clientId, "client id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.addPathSegment("credentials")
.build()
.toString();
BaseRequest<Credential> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Credential>() {
});
request.setBody(credential);
return request;
}
/**
* Get the client credentials associated with this application. A token with scope {@code read:client_credentials} is required.
* @param clientId the ID of the application
* @return a request to execute.
*/
public Request<List<Credential>> listCredentials(String clientId) {
Asserts.assertNotNull(clientId, "client id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.addPathSegment("credentials").build().toString();
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<List<Credential>>() {
});
}
/**
* Get a client credentials object. A token with scope {@code read:client_credentials} is required.
* @param clientId the ID of the application.
* @param credentialId the ID of the credential to retrieve.
* @return a request to execute.
*/
public Request<Credential> getCredential(String clientId, String credentialId) {
Asserts.assertNotNull(clientId, "client id");
Asserts.assertNotNull(credentialId, "credential id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.addPathSegment("credentials")
.addPathSegment(credentialId)
.build().toString();
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Credential>() {
});
}
/**
* Deletes a client credential. A token with scope {@code } is required.
* @param clientId the ID of the application.
* @param credentialId the ID of the credential to delete
* @return a request to execute.
*/
public Request<Void> deleteCredential(String clientId, String credentialId) {
Asserts.assertNotNull(clientId, "client id");
Asserts.assertNotNull(credentialId, "credential id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.addPathSegment("credentials")
.addPathSegment(credentialId)
.build()
.toString();
return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE);
}
/**
* Update an existing client credential. A token with scope update:client_credentials is needed.
* See https://auth0.com/docs/api/management/v2/clients/patch-credentials-by-credential-id
*
* @param clientId the application's client id.
* @param credentialId the ID of the credential.
* @param credential the credential to update.
* @return a Request to execute.
*/
public Request<Credential> updateCredential(String clientId, String credentialId, Credential credential) {
Asserts.assertNotNull(clientId, "client id");
Asserts.assertNotNull(credentialId, "credential id");
Asserts.assertNotNull(credential, "credential");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/clients")
.addPathSegment(clientId)
.addPathSegment("credentials")
.addPathSegment(credentialId)
.build()
.toString();
BaseRequest<Credential> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<Credential>() {
});
request.setBody(credential);
return request;
}
}