-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #431 from auth0/support-keys-mgmt-api
Added support for Key management API
- Loading branch information
Showing
10 changed files
with
511 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.auth0.client.mgmt; | ||
|
||
import com.auth0.json.mgmt.Key; | ||
import com.auth0.net.CustomRequest; | ||
import com.auth0.net.EmptyBodyRequest; | ||
import com.auth0.net.Request; | ||
import com.auth0.utils.Asserts; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Class that provides an implementation of the Keys methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Keys | ||
* <p> | ||
* This class is not thread-safe. | ||
* | ||
* @see ManagementAPI | ||
*/ | ||
public class KeysEntity extends BaseManagementEntity { | ||
|
||
KeysEntity(OkHttpClient client, HttpUrl baseUrl, | ||
String apiToken) { | ||
super(client, baseUrl, apiToken); | ||
} | ||
|
||
/** | ||
* Request all Application Signing Keys. | ||
* A token with read:signing_keys is needed | ||
* See https://auth0.com/docs/api/management/v2#!/Keys/get_signing_keys | ||
* | ||
* @return a Request to execute | ||
*/ | ||
public Request<List<Key>> list() { | ||
HttpUrl.Builder builder = baseUrl | ||
.newBuilder() | ||
.addEncodedPathSegments("api/v2/keys/signing"); | ||
String url = builder.build().toString(); | ||
CustomRequest<List<Key>> request = new CustomRequest<>(this.client, url, "GET", new TypeReference<List<Key>>() { | ||
}); | ||
request.addHeader("Authorization", "Bearer " + apiToken); | ||
return request; | ||
} | ||
|
||
|
||
/** | ||
* Request an Application Signing Key. A token with scope read:signing_keys is needed. | ||
* See https://auth0.com/docs/api/management/v2#!/Keys/get_signing_key | ||
* | ||
* @param kid the id of the Application Signing Key to retrieve. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Key> get(String kid) { | ||
Asserts.assertNotNull(kid, "kid"); | ||
|
||
HttpUrl.Builder builder = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/keys/signing") | ||
.addPathSegment(kid); | ||
String url = builder.build().toString(); | ||
CustomRequest<Key> request = new CustomRequest<>(client, url, "GET", new TypeReference<Key>() { | ||
}); | ||
request.addHeader("Authorization", "Bearer " + apiToken); | ||
return request; | ||
} | ||
|
||
/** | ||
* Rotate the Application Signing Key. | ||
* A token with scope create:signing_keys and update:signing_keys is needed. | ||
* See https://auth0.com/docs/api/management/v2#!/Keys/post_signing_keys | ||
* | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Key> rotate() { | ||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/keys/signing/rotate") | ||
.build() | ||
.toString(); | ||
CustomRequest<Key> request = new EmptyBodyRequest<>(this.client, url, "POST", new TypeReference<Key>() { | ||
}); | ||
request.addHeader("Authorization", "Bearer " + apiToken); | ||
return request; | ||
} | ||
|
||
/** | ||
* Revoke an Application Signing Key. | ||
* A token with scope update:signing_keys is needed. | ||
* See https://auth0.com/docs/api/management/v2#!/Keys/put_signing_keys | ||
* | ||
* @param kid the id of the Application Signing Key to revoke. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Key> revoke(String kid) { | ||
Asserts.assertNotNull(kid, "kid"); | ||
|
||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/keys/signing/") | ||
.addPathSegment(kid) | ||
.addPathSegment("revoke") | ||
.build() | ||
.toString(); | ||
CustomRequest<Key> request = new EmptyBodyRequest<>(this.client, url, "PUT", new TypeReference<Key>() { | ||
}); | ||
request.addHeader("Authorization", "Bearer " + apiToken); | ||
return request; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
package com.auth0.json.mgmt; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Class that represents an Auth0 Key object. Related to the {@link com.auth0.client.mgmt.KeysEntity} entity. | ||
*/ | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class Key { | ||
|
||
@JsonProperty("kid") | ||
private String kid; | ||
|
||
@JsonProperty("cert") | ||
private String cert; | ||
|
||
@JsonProperty("pkcs7") | ||
private String pkcs7; | ||
|
||
@JsonProperty("current") | ||
private Boolean current; | ||
|
||
@JsonProperty("next") | ||
private Boolean next; | ||
|
||
@JsonProperty("previous") | ||
private Boolean previous; | ||
|
||
@JsonProperty("fingerprint") | ||
private String fingerprint; | ||
|
||
@JsonProperty("thumbprint") | ||
private String thumbprint; | ||
|
||
@JsonProperty("revoked") | ||
private Boolean revoked; | ||
|
||
@JsonProperty("current_since") | ||
@JsonFormat(shape = JsonFormat.Shape.STRING) | ||
private Date currentSince; | ||
|
||
@JsonProperty("current_until") | ||
@JsonFormat(shape = JsonFormat.Shape.STRING) | ||
private Date currentUntil; | ||
|
||
@JsonProperty("revoked_at") | ||
@JsonFormat(shape = JsonFormat.Shape.STRING) | ||
private Date revokedAt; | ||
|
||
@JsonProperty("kid") | ||
public String getKid() { | ||
return kid; | ||
} | ||
|
||
@JsonProperty("kid") | ||
public void setKid(String kid) { | ||
this.kid = kid; | ||
} | ||
|
||
@JsonProperty("cert") | ||
public String getCert() { | ||
return cert; | ||
} | ||
|
||
@JsonProperty("cert") | ||
public void setCert(String cert) { | ||
this.cert = cert; | ||
} | ||
|
||
@JsonProperty("pkcs7") | ||
public String getPkcs7() { | ||
return pkcs7; | ||
} | ||
|
||
@JsonProperty("pkcs7") | ||
public void setPkcs7(String pkcs7) { | ||
this.pkcs7 = pkcs7; | ||
} | ||
|
||
@JsonProperty("current") | ||
public Boolean getCurrent() { | ||
return current; | ||
} | ||
|
||
@JsonProperty("current") | ||
public void setCurrent(Boolean current) { | ||
this.current = current; | ||
} | ||
|
||
@JsonProperty("next") | ||
public Boolean getNext() { | ||
return next; | ||
} | ||
|
||
@JsonProperty("next") | ||
public void setNext(Boolean next) { | ||
this.next = next; | ||
} | ||
|
||
@JsonProperty("previous") | ||
public Boolean getPrevious() { | ||
return previous; | ||
} | ||
|
||
@JsonProperty("previous") | ||
public void setPrevious(Boolean previous) { | ||
this.previous = previous; | ||
} | ||
|
||
@JsonProperty("fingerprint") | ||
public String getFingerprint() { | ||
return fingerprint; | ||
} | ||
|
||
@JsonProperty("fingerprint") | ||
public void setFingerprint(String fingerprint) { | ||
this.fingerprint = fingerprint; | ||
} | ||
|
||
@JsonProperty("thumbprint") | ||
public String getThumbprint() { | ||
return thumbprint; | ||
} | ||
|
||
@JsonProperty("thumbprint") | ||
public void setThumbprint(String thumbprint) { | ||
this.thumbprint = thumbprint; | ||
} | ||
|
||
@JsonProperty("revoked") | ||
public Boolean getRevoked() { | ||
return revoked; | ||
} | ||
|
||
@JsonProperty("revoked") | ||
public void setRevoked(Boolean revoked) { | ||
this.revoked = revoked; | ||
} | ||
|
||
@JsonProperty("current_since") | ||
public Date getCurrentSince() { | ||
return currentSince; | ||
} | ||
|
||
@JsonProperty("current_since") | ||
public void setCurrentSince(Date currentSince) { | ||
this.currentSince = currentSince; | ||
} | ||
|
||
@JsonProperty("current_until") | ||
public Date getCurrentUntil() { | ||
return currentUntil; | ||
} | ||
|
||
@JsonProperty("current_until") | ||
public void setCurrentUntil(Date currentUntil) { | ||
this.currentUntil = currentUntil; | ||
} | ||
|
||
@JsonProperty("revoked_at") | ||
public Date getRevokedAt() { | ||
return revokedAt; | ||
} | ||
|
||
@JsonProperty("revoked_at") | ||
public void setRevokedAt(Date revokedAt) { | ||
this.revokedAt = revokedAt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.