-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for custom prompts (#680)
- Loading branch information
Showing
8 changed files
with
440 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
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,162 @@ | ||
package com.auth0.client.mgmt; | ||
|
||
import com.auth0.json.mgmt.prompts.Prompt; | ||
import com.auth0.net.BaseRequest; | ||
import com.auth0.net.Request; | ||
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; | ||
|
||
public class PromptsEntity extends BaseManagementEntity { | ||
|
||
private final static String ORGS_PATH = "api/v2/prompts"; | ||
|
||
PromptsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { | ||
super(client, baseUrl, tokenProvider); | ||
} | ||
|
||
/** | ||
* Get the prompt. | ||
* A token with {@code read:prompts} scope is required. | ||
* @return a Request to execute. | ||
* | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-prompts">https://auth0.com/docs/api/management/v2#!/prompts/get-prompts</a> | ||
*/ | ||
public Request<Prompt> getPrompt() { | ||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH); | ||
String url = builder.build().toString(); | ||
|
||
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Prompt>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Update the prompt. | ||
* A token with {@code update:prompts} scope is required. | ||
* @param prompt the prompt to update. | ||
* @return a Request to execute. | ||
* | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/patch-prompts">https://auth0.com/docs/api/management/v2#!/prompts/patch-prompts</a> | ||
*/ | ||
public Request<Prompt> updatePrompt(Prompt prompt) { | ||
Asserts.assertNotNull(prompt, "prompt"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH); | ||
String url = builder.build().toString(); | ||
|
||
BaseRequest<Prompt> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<Prompt>() { | ||
}); | ||
|
||
request.setBody(prompt); | ||
return request; | ||
} | ||
|
||
/** | ||
* Get the custom text for specific prompt and language. | ||
* A token with {@code read:prompts} scope is required. | ||
* @param prompt the prompt name. | ||
* @param language the language. | ||
* @return a Request to execute. | ||
* | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-custom-text-by-language">https://auth0.com/docs/api/management/v2#!/prompts/get-custom-text-by-language</a> | ||
*/ | ||
public Request<Object> getCustomText(String prompt, String language) { | ||
Asserts.assertNotNull(prompt, "prompt"); | ||
Asserts.assertNotNull(language, "language"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(prompt) | ||
.addPathSegment("custom-text") | ||
.addPathSegments(language); | ||
|
||
String url = builder.build().toString(); | ||
|
||
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Set the custom text for specific prompt and language. | ||
* A token with {@code update:prompts} scope is required. | ||
* @param prompt the prompt name. | ||
* @param language the language. | ||
* @param customText the custom text. | ||
* @return a Request to execute. | ||
* | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/put-custom-text-by-language">https://auth0.com/docs/api/management/v2#!/prompts/put-custom-text-by-language</a> | ||
*/ | ||
public Request<Void> setCustomText(String prompt, String language, Object customText) { | ||
Asserts.assertNotNull(prompt, "prompt"); | ||
Asserts.assertNotNull(language, "language"); | ||
Asserts.assertNotNull(customText, "customText"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(prompt) | ||
.addPathSegment("custom-text") | ||
.addPathSegments(language); | ||
|
||
String url = builder.build().toString(); | ||
|
||
BaseRequest<Void> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Void>() { | ||
}); | ||
|
||
request.setBody(customText); | ||
return request; | ||
} | ||
|
||
/** | ||
* Get the partials for specific prompt. | ||
* A token with {@code read:prompts} scope is required. | ||
* @param prompt the prompt name. | ||
* @return a Request to execute. | ||
* | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-partialse">https://auth0.com/docs/api/management/v2#!/prompts/get-partials</a> | ||
*/ | ||
public Request<Object> getPartialsPrompt(String prompt) { | ||
Asserts.assertNotNull(prompt, "prompt"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(prompt) | ||
.addPathSegment("partials"); | ||
|
||
String url = builder.build().toString(); | ||
|
||
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Set the partials for specific prompt. | ||
* A token with {@code read:prompts} scope is required. | ||
* @param prompt the prompt name. | ||
* @param partials the partials. | ||
* @return a Request to execute. | ||
* | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/put-partials">https://auth0.com/docs/api/management/v2#!/prompts/put-partials</a> | ||
*/ | ||
public Request<Void> setPartialsPrompt(String prompt, Object partials) { | ||
Asserts.assertNotNull(prompt, "prompt"); | ||
Asserts.assertNotNull(partials, "partials"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(prompt) | ||
.addPathSegment("partials"); | ||
|
||
String url = builder.build().toString(); | ||
|
||
BaseRequest<Void> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Void>() { | ||
}); | ||
|
||
request.setBody(partials); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.auth0.json.mgmt.prompts; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class Prompt { | ||
@JsonProperty("universal_login_experience") | ||
private String universalLoginExperience; | ||
@JsonProperty("identifier_first") | ||
private boolean identifierFirst; | ||
@JsonProperty("webauthn_platform_first_factor") | ||
private boolean webauthnPlatformFirstFactor; | ||
|
||
/** | ||
* Getter for the universal login experience. | ||
* @return the universal login experience. | ||
*/ | ||
public String getUniversalLoginExperience() { | ||
return universalLoginExperience; | ||
} | ||
|
||
/** | ||
* Setter for the universal login experience. | ||
* @param universalLoginExperience the universal login experience to set. | ||
*/ | ||
public void setUniversalLoginExperience(String universalLoginExperience) { | ||
this.universalLoginExperience = universalLoginExperience; | ||
} | ||
|
||
/** | ||
* Getter for the identifier first. | ||
* @return the identifier first. | ||
*/ | ||
public boolean isIdentifierFirst() { | ||
return identifierFirst; | ||
} | ||
|
||
/** | ||
* Setter for the identifier first. | ||
* @param identifierFirst the identifier first to set. | ||
*/ | ||
public void setIdentifierFirst(boolean identifierFirst) { | ||
this.identifierFirst = identifierFirst; | ||
} | ||
|
||
/** | ||
* Getter for the webauthn platform first factor. | ||
* @return the webauthn platform first factor. | ||
*/ | ||
public boolean isWebauthnPlatformFirstFactor() { | ||
return webauthnPlatformFirstFactor; | ||
} | ||
|
||
/** | ||
* Setter for the webauthn platform first factor. | ||
* @param webauthnPlatformFirstFactor the webauthn platform first factor to set. | ||
*/ | ||
public void setWebauthnPlatformFirstFactor(boolean webauthnPlatformFirstFactor) { | ||
this.webauthnPlatformFirstFactor = webauthnPlatformFirstFactor; | ||
} | ||
} |
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.