Skip to content

Commit aba2257

Browse files
authored
[SDK-3864] - Add support for client credential management (#525)
1 parent b11a955 commit aba2257

12 files changed

Lines changed: 662 additions & 2 deletions

File tree

src/main/java/com/auth0/client/mgmt/ClientsEntity.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.auth0.client.mgmt.filter.FieldsFilter;
55
import com.auth0.json.mgmt.client.Client;
66
import com.auth0.json.mgmt.client.ClientsPage;
7+
import com.auth0.json.mgmt.client.Credential;
78
import com.auth0.net.EmptyBodyRequest;
89
import com.auth0.net.BaseRequest;
910
import com.auth0.net.Request;
@@ -182,4 +183,86 @@ public Request<Client> rotateSecret(String clientId) {
182183
return new EmptyBodyRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Client>() {
183184
});
184185
}
186+
187+
/**
188+
* Creates an Application's client credential. A token with scope {@code create:client_credentials} is required.
189+
*
190+
* @param clientId the application's client id.
191+
* @param credential the credential to create.
192+
* @return a Request to execute.
193+
*/
194+
public Request<Credential> createCredential(String clientId, Credential credential) {
195+
Asserts.assertNotNull(clientId, "client id");
196+
197+
String url = baseUrl
198+
.newBuilder()
199+
.addPathSegments("api/v2/clients")
200+
.addPathSegment(clientId)
201+
.addPathSegment("credentials")
202+
.build()
203+
.toString();
204+
BaseRequest<Credential> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Credential>() {
205+
});
206+
request.setBody(credential);
207+
return request;
208+
}
209+
210+
/**
211+
* Get the client credentials associated with this application. A token with scope {@code read:client_credentials} is required.
212+
* @param clientId the ID of the application
213+
* @return a request to execute.
214+
*/
215+
public Request<List<Credential>> listCredentials(String clientId) {
216+
Asserts.assertNotNull(clientId, "client id");
217+
String url = baseUrl
218+
.newBuilder()
219+
.addPathSegments("api/v2/clients")
220+
.addPathSegment(clientId)
221+
.addPathSegment("credentials").build().toString();
222+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<List<Credential>>() {
223+
});
224+
}
225+
226+
/**
227+
* Get a client credentials object. A token with scope {@code read:client_credentials} is required.
228+
* @param clientId the ID of the application.
229+
* @param credentialId the ID of the credential to retrieve.
230+
* @return a request to execute.
231+
*/
232+
public Request<Credential> getCredential(String clientId, String credentialId) {
233+
Asserts.assertNotNull(clientId, "client id");
234+
Asserts.assertNotNull(credentialId, "credential id");
235+
236+
String url = baseUrl
237+
.newBuilder()
238+
.addPathSegments("api/v2/clients")
239+
.addPathSegment(clientId)
240+
.addPathSegment("credentials")
241+
.addPathSegment(credentialId)
242+
.build().toString();
243+
244+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Credential>() {
245+
});
246+
}
247+
248+
/**
249+
* Deletes a client credential. A token with scope {@code } is required.
250+
* @param clientId the ID of the application.
251+
* @param credentialId the ID of the credential to delete
252+
* @return a request to execute.
253+
*/
254+
public Request<Void> deleteCredential(String clientId, String credentialId) {
255+
Asserts.assertNotNull(clientId, "client id");
256+
Asserts.assertNotNull(credentialId, "credential id");
257+
258+
String url = baseUrl
259+
.newBuilder()
260+
.addPathSegments("api/v2/clients")
261+
.addPathSegment(clientId)
262+
.addPathSegment("credentials")
263+
.addPathSegment(credentialId)
264+
.build()
265+
.toString();
266+
return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE);
267+
}
185268
}

src/main/java/com/auth0/json/mgmt/client/Client.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public class Client {
9090
private Boolean crossOriginAuth;
9191
@JsonProperty("cross_origin_loc")
9292
private String crossOriginLoc;
93+
@JsonProperty("client_authentication_methods")
94+
private ClientAuthenticationMethods clientAuthenticationMethods;
9395

9496
/**
9597
* Getter for the name of the tenant this client belongs to.
@@ -793,5 +795,13 @@ public void setCrossOriginLoc(String crossOriginLoc) {
793795
public String getCrossOriginLoc() {
794796
return crossOriginLoc;
795797
}
798+
799+
public void setClientAuthenticationMethods(ClientAuthenticationMethods clientAuthenticationMethods) {
800+
this.clientAuthenticationMethods = clientAuthenticationMethods;
801+
}
802+
803+
public ClientAuthenticationMethods getClientAuthenticationMethods() {
804+
return clientAuthenticationMethods;
805+
}
796806
}
797807

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.auth0.json.mgmt.client;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
/**
8+
* Class that represents an Auth0 Application authentication methods. Related to the {@link com.auth0.client.mgmt.ClientsEntity} entity.
9+
*/
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
@JsonInclude(JsonInclude.Include.NON_NULL)
12+
public class ClientAuthenticationMethods {
13+
14+
@JsonProperty("private_key_jwt")
15+
private PrivateKeyJwt privateKeyJwt;
16+
17+
public ClientAuthenticationMethods() {
18+
19+
}
20+
21+
public ClientAuthenticationMethods(PrivateKeyJwt privateKeyJwt) {
22+
this.privateKeyJwt = privateKeyJwt;
23+
}
24+
25+
public PrivateKeyJwt getPrivateKeyJwt() {
26+
return privateKeyJwt;
27+
}
28+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package com.auth0.json.mgmt.client;
2+
3+
import com.fasterxml.jackson.annotation.JsonFormat;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
import java.util.Date;
9+
10+
/**
11+
* Class that represents an Auth0 application credential object. Related to the {@link com.auth0.client.mgmt.ClientsEntity} entity.
12+
*/
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
@JsonInclude(JsonInclude.Include.NON_NULL)
15+
public class Credential {
16+
17+
@JsonProperty("credential_type")
18+
private String credentialType;
19+
@JsonProperty("name")
20+
private String name;
21+
@JsonProperty("pem")
22+
private String pem;
23+
24+
@JsonProperty("id")
25+
private String id;
26+
@JsonProperty("kid")
27+
private String kid;
28+
@JsonProperty("thumbprint")
29+
private String thumbprint;
30+
@JsonProperty("alg")
31+
private String alg;
32+
@JsonProperty("parse_expiry_from_cert")
33+
private Boolean parseExpiryFromCert;
34+
@JsonFormat(shape = JsonFormat.Shape.STRING)
35+
@JsonProperty("created_at")
36+
private Date createdAt;
37+
@JsonFormat(shape = JsonFormat.Shape.STRING)
38+
@JsonProperty("updated_at")
39+
private Date updatedAt;
40+
@JsonFormat(shape = JsonFormat.Shape.STRING)
41+
@JsonProperty("expires_at")
42+
private Date expiresAt;
43+
44+
/**
45+
* Create a new credential
46+
* @param credentialType the credential type
47+
* @param pem the PEM
48+
*/
49+
public Credential(String credentialType, String pem) {
50+
this.credentialType = credentialType;
51+
this.pem = pem;
52+
}
53+
54+
/**
55+
* Create a new credential
56+
* @param id the ID of the credential
57+
*/
58+
public Credential(String id) {
59+
this.id = id;
60+
}
61+
62+
/**
63+
* Create a new credential
64+
*/
65+
public Credential() {}
66+
67+
/**
68+
* @return the credential type
69+
*/
70+
public String getCredentialType() {
71+
return credentialType;
72+
}
73+
74+
/**
75+
* Sets the credential type
76+
* @param credentialType the credential type
77+
*/
78+
public void setCredentialType(String credentialType) {
79+
this.credentialType = credentialType;
80+
}
81+
82+
/**
83+
* @return the credential name
84+
*/
85+
public String getName() {
86+
return name;
87+
}
88+
89+
/**
90+
* Sets the credential name
91+
* @param name the name of the credential
92+
*/
93+
public void setName(String name) {
94+
this.name = name;
95+
}
96+
97+
/**
98+
* @return the credential's PEM
99+
*/
100+
public String getPem() {
101+
return pem;
102+
}
103+
104+
/**
105+
* Sets the credential's PEM
106+
* @param pem the PEM of the credential
107+
*/
108+
public void setPem(String pem) {
109+
this.pem = pem;
110+
}
111+
112+
/**
113+
* @return the ID of the credential
114+
*/
115+
public String getId() {
116+
return id;
117+
}
118+
119+
/**
120+
* @return the KID of the credential
121+
*/
122+
public String getKid() {
123+
return kid;
124+
}
125+
126+
/**
127+
* @return the thumbprint of the credential
128+
*/
129+
public String getThumbprint() {
130+
return thumbprint;
131+
}
132+
133+
/**
134+
* @return the date the credential was created at
135+
*/
136+
public Date getCreatedAt() {
137+
return createdAt;
138+
}
139+
140+
/**
141+
* @return the algorithm of this credential
142+
*/
143+
public String getAlg() {
144+
return alg;
145+
}
146+
147+
/**
148+
* Set the algorithm
149+
* @param alg the algorithm
150+
*/
151+
public void setAlg(String alg) {
152+
this.alg = alg;
153+
}
154+
155+
/**
156+
* @return the time this credential was last updated
157+
*/
158+
public Date getUpdatedAt() {
159+
return updatedAt;
160+
}
161+
162+
/**
163+
* @return the expiration time of this credential
164+
*/
165+
public Date getExpiresAt() {
166+
return expiresAt;
167+
}
168+
169+
/**
170+
* Set the expires_at value for this credential
171+
* @param expiresAt the time this credential should expire
172+
*/
173+
public void setExpiresAt(Date expiresAt) {
174+
this.expiresAt = expiresAt;
175+
}
176+
177+
/**
178+
* @return whether the expiry will be parsed from the x509 certificate
179+
*/
180+
public Boolean getParseExpiryFromCert() {
181+
return parseExpiryFromCert;
182+
}
183+
184+
/**
185+
* Whether to parse expiry from x509 certificate
186+
* @param parseExpiryFromCert true to parse expiry; false otherwise.
187+
*/
188+
public void setParseExpiryFromCert(Boolean parseExpiryFromCert) {
189+
this.parseExpiryFromCert = parseExpiryFromCert;
190+
}
191+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.auth0.json.mgmt.client;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
import java.util.List;
8+
9+
/**
10+
* Class that represents an Auth0 Application private key JWT authentication method. Related to the {@link com.auth0.client.mgmt.ClientsEntity} entity.
11+
*/
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
@JsonInclude(JsonInclude.Include.NON_NULL)
14+
public class PrivateKeyJwt {
15+
16+
@JsonProperty("credentials")
17+
private List<Credential> credentials;
18+
19+
/**
20+
* Create a new instance
21+
*/
22+
public PrivateKeyJwt() {}
23+
24+
/**
25+
* Create a new instance
26+
* @param credentials the credentials to use
27+
*/
28+
public PrivateKeyJwt(List<Credential> credentials) {
29+
this.credentials = credentials;
30+
}
31+
32+
/**
33+
* @return the credentials
34+
*/
35+
public List<Credential> getCredentials() {
36+
return credentials;
37+
}
38+
}

src/test/java/com/auth0/client/MockServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class MockServer {
3939
public static final String MGMT_CLIENTS_LIST = "src/test/resources/mgmt/clients_list.json";
4040
public static final String MGMT_CLIENTS_PAGED_LIST = "src/test/resources/mgmt/clients_paged_list.json";
4141
public static final String MGMT_CLIENT = "src/test/resources/mgmt/client.json";
42+
public static final String MGMT_CLIENT_CREDENTIAL = "src/test/resources/mgmt/client_credential.json";
43+
public static final String MGMT_CLIENT_CREDENTIAL_LIST = "src/test/resources/mgmt/client_credential_list.json";
4244
public static final String MGMT_CONNECTIONS_LIST = "src/test/resources/mgmt/connections_list.json";
4345
public static final String MGMT_CONNECTIONS_PAGED_LIST = "src/test/resources/mgmt/connections_paged_list.json";
4446
public static final String MGMT_CONNECTION = "src/test/resources/mgmt/connection.json";

0 commit comments

Comments
 (0)