Skip to content

Commit

Permalink
Add refresh token configuration object to client (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Uskoski authored Nov 19, 2020
1 parent 9ebdfdd commit 19b617f
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/main/java/com/auth0/json/mgmt/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class Client {
private Map<String, Object> clientMetadata;
@JsonProperty("mobile")
private Mobile mobile;
@JsonProperty("refresh_token")
private RefreshToken refreshToken;

/**
* Creates a new Application instance setting the name property.
Expand Down Expand Up @@ -657,5 +659,23 @@ public Mobile getMobile() {
public void setMobile(Mobile mobile) {
this.mobile = mobile;
}

/**
* Getter for the configuration related to refresh tokens.
*
* @return the refresh token configuration.
*/
public RefreshToken getRefreshToken() {
return refreshToken;
}

/**
* Setter for the configuration related to refresh tokens.
*
* @param refreshToken the refresh token configuration to set.
*/
public void setRefreshToken(RefreshToken refreshToken) {
this.refreshToken = refreshToken;
}
}

176 changes: 176 additions & 0 deletions src/main/java/com/auth0/json/mgmt/client/RefreshToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package com.auth0.json.mgmt.client;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Class that represents the configuration of refresh tokens for a client.
*/
@SuppressWarnings({"unused", "WeakerAccess"})
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RefreshToken {

@JsonProperty("rotation_type")
private String rotationType;
@JsonProperty("expiration_type")
private String expirationType;
@JsonProperty("leeway")
private Integer leeway;
@JsonProperty("token_lifetime")
private Integer tokenLifetime;
@JsonProperty("infinite_token_lifetime")
private Boolean infiniteTokenLifetime;
@JsonProperty("idle_token_lifetime")
private Integer idleTokenLifetime;
@JsonProperty("infinite_idle_token_lifetime")
private Boolean infiniteIdleTokenLifetime;

/**
* Getter for the rotation type of the refresh token.
*
* @return the rotation type.
*/
@JsonProperty("rotation_type")
public String getRotationType() {
return rotationType;
}

/**
* Setter for the rotation type of the refresh token.
*
* @param rotationType the rotation type to set.
*/
@JsonProperty("rotation_type")
public void setRotationType(String rotationType) {
this.rotationType = rotationType;
}

/**
* Getter for the expiration type of the refresh token.
*
* @return the expiration type.
*/
@JsonProperty("expiration_type")
public String getExpirationType() {
return expirationType;
}

/**
* Setter for the expiration type of the refresh token.
*
* @param expirationType the expiration type to set.
*/
@JsonProperty("expiration_type")
public void setExpirationType(String expirationType) {
this.expirationType = expirationType;
}

/**
* Getter for the period in seconds where the previous refresh token can be exchanged without
* triggering breach detection.
*
* @return the leeway in seconds.
*/
@JsonProperty("leeway")
public Integer getLeeway() {
return leeway;
}

/**
* Setter for the period in seconds where the previous refresh token can be exchanged without
* triggering breach detection.
*
* @param leeway the leeway in seconds.
*/
@JsonProperty("leeway")
public void setLeeway(Integer leeway) {
this.leeway = leeway;
}

/**
* Getter for the period in seconds for which refresh tokens will remain valid.
*
* @return a token's lifetime in seconds.
*/
@JsonProperty("token_lifetime")
public Integer getTokenLifetime() {
return tokenLifetime;
}

/**
* Setter for the period in seconds for which refresh tokens will remain valid.
*
* @param tokenLifetime a token's lifetime in seconds.
*/
@JsonProperty("token_lifetime")
public void setTokenLifetime(Integer tokenLifetime) {
this.tokenLifetime = tokenLifetime;
}

/**
* Getter for determining whether tokens have a set lifetime or not. This takes precedence over
* token_lifetime values.
*
* @return true if tokens do not have a set lifetime, false otherwise.
*/
@JsonProperty("infinite_token_lifetime")
public Boolean getInfiniteTokenLifetime() {
return infiniteTokenLifetime;
}

/**
* Setter for determining whether tokens have a set lifetime or not. This takes precedence over
* token_lifetime values.
*
* @param infiniteTokenLifetime true if tokens do not have a set lifetime, false otherwise.
*/
@JsonProperty("infinite_token_lifetime")
public void setInfiniteTokenLifetime(Boolean infiniteTokenLifetime) {
this.infiniteTokenLifetime = infiniteTokenLifetime;
}

/**
* Getter for the period in seconds for which refresh tokens will remain valid without use.
*
* @return a token's lifetime without use in seconds.
*/
@JsonProperty("idle_token_lifetime")
public Integer getIdleTokenLifetime() {
return idleTokenLifetime;
}

/**
* Setter for the period in seconds for which refresh tokens will remain valid without use.
*
* @param idleTokenLifetime a token's lifetime without use in seconds.
*/
@JsonProperty("idle_token_lifetime")
public void setIdleTokenLifetime(Integer idleTokenLifetime) {
this.idleTokenLifetime = idleTokenLifetime;
}

/**
* Getter for determining whether tokens expire without use or not. This takes precedence over
* idle_token_lifetime values.
*
* @return true if tokens do not expire from lack of use, false otherwise.
*/
@JsonProperty("infinite_idle_token_lifetime")
public Boolean getInfiniteIdleTokenLifetime() {
return infiniteIdleTokenLifetime;
}

/**
* Setter for determining whether tokens expire without use or not. This takes precedence over
* idle_token_lifetime values.
*
* @param infiniteIdleTokenLifetime true if tokens do not expire from lack of use, false
* otherwise.
*/
@JsonProperty("infinite_idle_token_lifetime")
public void setInfiniteIdleTokenLifetime(Boolean infiniteIdleTokenLifetime) {
this.infiniteIdleTokenLifetime = infiniteIdleTokenLifetime;
}
}
6 changes: 5 additions & 1 deletion src/test/java/com/auth0/json/mgmt/client/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class ClientTest extends JsonTest<Client> {

private static final String readOnlyJson = "{\"client_id\":\"clientId\",\"is_heroku_app\":true,\"signing_keys\":[{\"cert\":\"ce\",\"pkcs7\":\"pk\",\"subject\":\"su\"}]}";
private static final String json = "{\"name\":\"name\",\"description\":\"description\",\"client_secret\":\"secret\",\"app_type\":\"type\",\"logo_uri\":\"uri\",\"oidc_conformant\":true,\"is_first_party\":true,\"initiate_login_uri\":\"https://myhome.com/login\",\"callbacks\":[\"value\"],\"allowed_origins\":[\"value\"],\"web_origins\":[\"value\"],\"grant_types\":[\"value\"],\"client_aliases\":[\"value\"],\"allowed_clients\":[\"value\"],\"allowed_logout_urls\":[\"value\"],\"jwt_configuration\":{\"lifetime_in_seconds\":100,\"scopes\":\"openid\",\"alg\":\"alg\"},\"encryption_key\":{\"pub\":\"pub\",\"cert\":\"cert\"},\"sso\":true,\"sso_disabled\":true,\"custom_login_page_on\":true,\"custom_login_page\":\"custom\",\"custom_login_page_preview\":\"preview\",\"form_template\":\"template\",\"addons\":{\"rms\":{},\"mscrm\":{},\"slack\":{},\"layer\":{}},\"token_endpoint_auth_method\":\"method\",\"client_metadata\":{\"key\":\"value\"},\"mobile\":{\"android\":{\"app_package_name\":\"pkg\",\"sha256_cert_fingerprints\":[\"256\"]},\"ios\":{\"team_id\":\"team\",\"app_bundle_identifier\":\"id\"}}}";
private static final String json = "{\"name\":\"name\",\"description\":\"description\",\"client_secret\":\"secret\",\"app_type\":\"type\",\"logo_uri\":\"uri\",\"oidc_conformant\":true,\"is_first_party\":true,\"initiate_login_uri\":\"https://myhome.com/login\",\"callbacks\":[\"value\"],\"allowed_origins\":[\"value\"],\"web_origins\":[\"value\"],\"grant_types\":[\"value\"],\"client_aliases\":[\"value\"],\"allowed_clients\":[\"value\"],\"allowed_logout_urls\":[\"value\"],\"jwt_configuration\":{\"lifetime_in_seconds\":100,\"scopes\":\"openid\",\"alg\":\"alg\"},\"encryption_key\":{\"pub\":\"pub\",\"cert\":\"cert\"},\"sso\":true,\"sso_disabled\":true,\"custom_login_page_on\":true,\"custom_login_page\":\"custom\",\"custom_login_page_preview\":\"preview\",\"form_template\":\"template\",\"addons\":{\"rms\":{},\"mscrm\":{},\"slack\":{},\"layer\":{}},\"token_endpoint_auth_method\":\"method\",\"client_metadata\":{\"key\":\"value\"},\"mobile\":{\"android\":{\"app_package_name\":\"pkg\",\"sha256_cert_fingerprints\":[\"256\"]},\"ios\":{\"team_id\":\"team\",\"app_bundle_identifier\":\"id\"}},\"refresh_token\":{\"rotation_type\":\"non-rotating\"}}";

@Test
public void shouldSerialize() throws Exception {
Expand Down Expand Up @@ -54,6 +54,8 @@ public void shouldSerialize() throws Exception {
client.setClientMetadata(metadata);
Mobile mobile = new Mobile(new Android("pkg", Collections.singletonList("256")), new IOS("team", "id"));
client.setMobile(mobile);
RefreshToken refreshToken = new RefreshToken();
client.setRefreshToken(refreshToken);

String serialized = toJSON(client);
assertThat(serialized, is(notNullValue()));
Expand Down Expand Up @@ -84,6 +86,7 @@ public void shouldSerialize() throws Exception {
assertThat(serialized, JsonMatcher.hasEntry("token_endpoint_auth_method", "method"));
assertThat(serialized, JsonMatcher.hasEntry("client_metadata", notNullValue()));
assertThat(serialized, JsonMatcher.hasEntry("mobile", notNullValue()));
assertThat(serialized, JsonMatcher.hasEntry("refresh_token", notNullValue()));
}

@Test
Expand Down Expand Up @@ -124,6 +127,7 @@ public void shouldDeserialize() throws Exception {
assertThat(client.getTokenEndpointAuthMethod(), is("method"));
assertThat(client.getClientMetadata(), IsMapContaining.hasEntry("key", "value"));
assertThat(client.getMobile(), is(notNullValue()));
assertThat(client.getRefreshToken(), is(notNullValue()));
}

@Test
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/com/auth0/json/mgmt/client/RefreshTokenTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.auth0.json.mgmt.client;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import com.auth0.json.JsonMatcher;
import com.auth0.json.JsonTest;
import org.junit.Test;

public class RefreshTokenTest extends JsonTest<RefreshToken> {

private static final String json = "{\"rotation_type\":\"non-rotating\",\"expiration_type\":\"non-expiring\",\"leeway\":0,\"token_lifetime\":0,\"infinite_token_lifetime\":false,\"idle_token_lifetime\":0,\"infinite_idle_token_lifetime\":false}";

@Test
public void shouldSerialize() throws Exception {
RefreshToken refreshToken = new RefreshToken();
refreshToken.setRotationType("non-rotating");
refreshToken.setExpirationType("non-expiring");
refreshToken.setLeeway(0);
refreshToken.setTokenLifetime(0);
refreshToken.setInfiniteTokenLifetime(false);
refreshToken.setIdleTokenLifetime(0);
refreshToken.setInfiniteIdleTokenLifetime(false);

String serialized = toJSON(refreshToken);
assertThat(serialized, is(notNullValue()));
assertThat(serialized, JsonMatcher.hasEntry("rotation_type", "non-rotating"));
assertThat(serialized, JsonMatcher.hasEntry("expiration_type", "non-expiring"));
assertThat(serialized, JsonMatcher.hasEntry("leeway", 0));
assertThat(serialized, JsonMatcher.hasEntry("token_lifetime", 0));
assertThat(serialized, JsonMatcher.hasEntry("infinite_token_lifetime", false));
assertThat(serialized, JsonMatcher.hasEntry("idle_token_lifetime", 0));
assertThat(serialized, JsonMatcher.hasEntry("infinite_idle_token_lifetime", false));
}

@Test
public void shouldDeserialize() throws Exception {
RefreshToken refreshToken = fromJSON(json, RefreshToken.class);

assertThat(refreshToken, is(notNullValue()));
assertThat(refreshToken.getRotationType(), is("non-rotating"));
assertThat(refreshToken.getExpirationType(), is("non-expiring"));
assertThat(refreshToken.getLeeway(), is(0));
assertThat(refreshToken.getTokenLifetime(), is(0));
assertThat(refreshToken.getInfiniteTokenLifetime(), is(false));
assertThat(refreshToken.getIdleTokenLifetime(), is(0));
assertThat(refreshToken.getInfiniteIdleTokenLifetime(), is(false));
}
}

0 comments on commit 19b617f

Please sign in to comment.