Skip to content

Commit 4ad68f1

Browse files
authored
Added support for custom prompts (#680)
1 parent 9c484d3 commit 4ad68f1

File tree

8 files changed

+440
-0
lines changed

8 files changed

+440
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ public SessionsEntity sessions() {
380380
return new SessionsEntity(client, baseUrl, tokenProvider);
381381
}
382382

383+
/**
384+
* Getter for the Prompts Entity
385+
* @return the Prompts Entity
386+
*/
387+
public PromptsEntity prompts() {
388+
return new PromptsEntity(client, baseUrl, tokenProvider);
389+
}
390+
383391
/**
384392
* Builder for {@link ManagementAPI} API client instances.
385393
*/
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package com.auth0.client.mgmt;
2+
3+
import com.auth0.json.mgmt.prompts.Prompt;
4+
import com.auth0.net.BaseRequest;
5+
import com.auth0.net.Request;
6+
import com.auth0.net.client.Auth0HttpClient;
7+
import com.auth0.net.client.HttpMethod;
8+
import com.auth0.utils.Asserts;
9+
import com.fasterxml.jackson.core.type.TypeReference;
10+
import okhttp3.HttpUrl;
11+
12+
public class PromptsEntity extends BaseManagementEntity {
13+
14+
private final static String ORGS_PATH = "api/v2/prompts";
15+
16+
PromptsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) {
17+
super(client, baseUrl, tokenProvider);
18+
}
19+
20+
/**
21+
* Get the prompt.
22+
* A token with {@code read:prompts} scope is required.
23+
* @return a Request to execute.
24+
*
25+
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-prompts">https://auth0.com/docs/api/management/v2#!/prompts/get-prompts</a>
26+
*/
27+
public Request<Prompt> getPrompt() {
28+
HttpUrl.Builder builder = baseUrl.newBuilder()
29+
.addPathSegments(ORGS_PATH);
30+
String url = builder.build().toString();
31+
32+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Prompt>() {
33+
});
34+
}
35+
36+
/**
37+
* Update the prompt.
38+
* A token with {@code update:prompts} scope is required.
39+
* @param prompt the prompt to update.
40+
* @return a Request to execute.
41+
*
42+
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/patch-prompts">https://auth0.com/docs/api/management/v2#!/prompts/patch-prompts</a>
43+
*/
44+
public Request<Prompt> updatePrompt(Prompt prompt) {
45+
Asserts.assertNotNull(prompt, "prompt");
46+
47+
HttpUrl.Builder builder = baseUrl.newBuilder()
48+
.addPathSegments(ORGS_PATH);
49+
String url = builder.build().toString();
50+
51+
BaseRequest<Prompt> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<Prompt>() {
52+
});
53+
54+
request.setBody(prompt);
55+
return request;
56+
}
57+
58+
/**
59+
* Get the custom text for specific prompt and language.
60+
* A token with {@code read:prompts} scope is required.
61+
* @param prompt the prompt name.
62+
* @param language the language.
63+
* @return a Request to execute.
64+
*
65+
* @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>
66+
*/
67+
public Request<Object> getCustomText(String prompt, String language) {
68+
Asserts.assertNotNull(prompt, "prompt");
69+
Asserts.assertNotNull(language, "language");
70+
71+
HttpUrl.Builder builder = baseUrl.newBuilder()
72+
.addPathSegments(ORGS_PATH)
73+
.addPathSegment(prompt)
74+
.addPathSegment("custom-text")
75+
.addPathSegments(language);
76+
77+
String url = builder.build().toString();
78+
79+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() {
80+
});
81+
}
82+
83+
/**
84+
* Set the custom text for specific prompt and language.
85+
* A token with {@code update:prompts} scope is required.
86+
* @param prompt the prompt name.
87+
* @param language the language.
88+
* @param customText the custom text.
89+
* @return a Request to execute.
90+
*
91+
* @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>
92+
*/
93+
public Request<Void> setCustomText(String prompt, String language, Object customText) {
94+
Asserts.assertNotNull(prompt, "prompt");
95+
Asserts.assertNotNull(language, "language");
96+
Asserts.assertNotNull(customText, "customText");
97+
98+
HttpUrl.Builder builder = baseUrl.newBuilder()
99+
.addPathSegments(ORGS_PATH)
100+
.addPathSegment(prompt)
101+
.addPathSegment("custom-text")
102+
.addPathSegments(language);
103+
104+
String url = builder.build().toString();
105+
106+
BaseRequest<Void> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Void>() {
107+
});
108+
109+
request.setBody(customText);
110+
return request;
111+
}
112+
113+
/**
114+
* Get the partials for specific prompt.
115+
* A token with {@code read:prompts} scope is required.
116+
* @param prompt the prompt name.
117+
* @return a Request to execute.
118+
*
119+
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-partialse">https://auth0.com/docs/api/management/v2#!/prompts/get-partials</a>
120+
*/
121+
public Request<Object> getPartialsPrompt(String prompt) {
122+
Asserts.assertNotNull(prompt, "prompt");
123+
124+
HttpUrl.Builder builder = baseUrl.newBuilder()
125+
.addPathSegments(ORGS_PATH)
126+
.addPathSegment(prompt)
127+
.addPathSegment("partials");
128+
129+
String url = builder.build().toString();
130+
131+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() {
132+
});
133+
}
134+
135+
/**
136+
* Set the partials for specific prompt.
137+
* A token with {@code read:prompts} scope is required.
138+
* @param prompt the prompt name.
139+
* @param partials the partials.
140+
* @return a Request to execute.
141+
*
142+
* @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/put-partials">https://auth0.com/docs/api/management/v2#!/prompts/put-partials</a>
143+
*/
144+
public Request<Void> setPartialsPrompt(String prompt, Object partials) {
145+
Asserts.assertNotNull(prompt, "prompt");
146+
Asserts.assertNotNull(partials, "partials");
147+
148+
HttpUrl.Builder builder = baseUrl.newBuilder()
149+
.addPathSegments(ORGS_PATH)
150+
.addPathSegment(prompt)
151+
.addPathSegment("partials");
152+
153+
String url = builder.build().toString();
154+
155+
BaseRequest<Void> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Void>() {
156+
});
157+
158+
request.setBody(partials);
159+
return request;
160+
}
161+
162+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.auth0.json.mgmt.prompts;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
@JsonIgnoreProperties(ignoreUnknown = true)
8+
@JsonInclude(JsonInclude.Include.NON_NULL)
9+
public class Prompt {
10+
@JsonProperty("universal_login_experience")
11+
private String universalLoginExperience;
12+
@JsonProperty("identifier_first")
13+
private boolean identifierFirst;
14+
@JsonProperty("webauthn_platform_first_factor")
15+
private boolean webauthnPlatformFirstFactor;
16+
17+
/**
18+
* Getter for the universal login experience.
19+
* @return the universal login experience.
20+
*/
21+
public String getUniversalLoginExperience() {
22+
return universalLoginExperience;
23+
}
24+
25+
/**
26+
* Setter for the universal login experience.
27+
* @param universalLoginExperience the universal login experience to set.
28+
*/
29+
public void setUniversalLoginExperience(String universalLoginExperience) {
30+
this.universalLoginExperience = universalLoginExperience;
31+
}
32+
33+
/**
34+
* Getter for the identifier first.
35+
* @return the identifier first.
36+
*/
37+
public boolean isIdentifierFirst() {
38+
return identifierFirst;
39+
}
40+
41+
/**
42+
* Setter for the identifier first.
43+
* @param identifierFirst the identifier first to set.
44+
*/
45+
public void setIdentifierFirst(boolean identifierFirst) {
46+
this.identifierFirst = identifierFirst;
47+
}
48+
49+
/**
50+
* Getter for the webauthn platform first factor.
51+
* @return the webauthn platform first factor.
52+
*/
53+
public boolean isWebauthnPlatformFirstFactor() {
54+
return webauthnPlatformFirstFactor;
55+
}
56+
57+
/**
58+
* Setter for the webauthn platform first factor.
59+
* @param webauthnPlatformFirstFactor the webauthn platform first factor to set.
60+
*/
61+
public void setWebauthnPlatformFirstFactor(boolean webauthnPlatformFirstFactor) {
62+
this.webauthnPlatformFirstFactor = webauthnPlatformFirstFactor;
63+
}
64+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public class MockServer {
8585
public static final String MGMT_USER = "src/test/resources/mgmt/user.json";
8686
public static final String MGMT_RECOVERY_CODE = "src/test/resources/mgmt/recovery_code.json";
8787
public static final String MGMT_IDENTITIES_LIST = "src/test/resources/mgmt/identities_list.json";
88+
public static final String MGMT_PROMPT = "src/test/resources/mgmt/prompt.json";
89+
public static final String MGMT_CUSTOM_TEXT_PROMPT = "src/test/resources/mgmt/custom_text_prompt.json";
90+
public static final String MGMT_PARTIALS_PROMPT = "src/test/resources/mgmt/partials_prompt.json";
8891
public static final String MGMT_GUARDIAN_AUTHENTICATION_POLICIES_LIST = "src/test/resources/mgmt/guardian_authentication_policies_list.json";
8992
public static final String MGMT_GUARDIAN_ENROLLMENT = "src/test/resources/mgmt/guardian_enrollment.json";
9093
public static final String MGMT_GUARDIAN_ENROLLMENTS_LIST = "src/test/resources/mgmt/guardian_enrollments_list.json";

0 commit comments

Comments
 (0)