Skip to content

Commit

Permalink
Added support for custom prompts (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanya732 authored Dec 3, 2024
1 parent 9c484d3 commit 4ad68f1
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/auth0/client/mgmt/ManagementAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ public SessionsEntity sessions() {
return new SessionsEntity(client, baseUrl, tokenProvider);
}

/**
* Getter for the Prompts Entity
* @return the Prompts Entity
*/
public PromptsEntity prompts() {
return new PromptsEntity(client, baseUrl, tokenProvider);
}

/**
* Builder for {@link ManagementAPI} API client instances.
*/
Expand Down
162 changes: 162 additions & 0 deletions src/main/java/com/auth0/client/mgmt/PromptsEntity.java
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;
}

}
64 changes: 64 additions & 0 deletions src/main/java/com/auth0/json/mgmt/prompts/Prompt.java
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;
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/auth0/client/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public class MockServer {
public static final String MGMT_USER = "src/test/resources/mgmt/user.json";
public static final String MGMT_RECOVERY_CODE = "src/test/resources/mgmt/recovery_code.json";
public static final String MGMT_IDENTITIES_LIST = "src/test/resources/mgmt/identities_list.json";
public static final String MGMT_PROMPT = "src/test/resources/mgmt/prompt.json";
public static final String MGMT_CUSTOM_TEXT_PROMPT = "src/test/resources/mgmt/custom_text_prompt.json";
public static final String MGMT_PARTIALS_PROMPT = "src/test/resources/mgmt/partials_prompt.json";
public static final String MGMT_GUARDIAN_AUTHENTICATION_POLICIES_LIST = "src/test/resources/mgmt/guardian_authentication_policies_list.json";
public static final String MGMT_GUARDIAN_ENROLLMENT = "src/test/resources/mgmt/guardian_enrollment.json";
public static final String MGMT_GUARDIAN_ENROLLMENTS_LIST = "src/test/resources/mgmt/guardian_enrollments_list.json";
Expand Down
Loading

0 comments on commit 4ad68f1

Please sign in to comment.