Skip to content

Commit 40f35f1

Browse files
authored
Added Support for Self-Service-Profile (#683)
1 parent 15367e7 commit 40f35f1

23 files changed

+1523
-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
@@ -388,6 +388,14 @@ public PromptsEntity prompts() {
388388
return new PromptsEntity(client, baseUrl, tokenProvider);
389389
}
390390

391+
/**
392+
* Getter for the SelfServiceProfiles Entity
393+
* @return the SelfServiceProfiles Entity
394+
*/
395+
public SelfServiceProfilesEntity selfServiceProfiles() {
396+
return new SelfServiceProfilesEntity(client, baseUrl, tokenProvider);
397+
}
398+
391399
/**
392400
* Builder for {@link ManagementAPI} API client instances.
393401
*/
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
package com.auth0.client.mgmt;
2+
3+
import com.auth0.client.mgmt.filter.PageBasedPaginationFilter;
4+
import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfile;
5+
import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponse;
6+
import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponsePage;
7+
import com.auth0.json.mgmt.selfserviceprofiles.SsoAccessTicketResponse;
8+
import com.auth0.net.*;
9+
import com.auth0.net.client.Auth0HttpClient;
10+
import com.auth0.net.client.HttpMethod;
11+
import com.auth0.utils.Asserts;
12+
import com.fasterxml.jackson.core.type.TypeReference;
13+
import okhttp3.HttpUrl;
14+
15+
import java.util.Map;
16+
17+
public class SelfServiceProfilesEntity extends BaseManagementEntity {
18+
19+
private final static String ORGS_PATH = "api/v2/self-service-profiles";
20+
21+
SelfServiceProfilesEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) {
22+
super(client, baseUrl, tokenProvider);
23+
}
24+
25+
/**
26+
* Request the list of self-service profiles.
27+
* A token with {@code read:self_service_profiles} scope is needed
28+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles</a>
29+
* @param pageFilter the pagination filter to apply. Can be null to use the default values.
30+
* @return a Request to execute.
31+
*/
32+
public Request<SelfServiceProfileResponsePage> get(PageBasedPaginationFilter pageFilter) {
33+
HttpUrl.Builder builder = baseUrl.newBuilder()
34+
.addPathSegments(ORGS_PATH);
35+
36+
if (pageFilter != null) {
37+
for (Map.Entry<String, Object> e : pageFilter.getAsMap().entrySet()) {
38+
builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue()));
39+
}
40+
}
41+
42+
String url = builder.build().toString();
43+
return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponsePage>() {
44+
});
45+
}
46+
47+
/**
48+
* Create a new self-service profile.
49+
* A token with {@code create:self_service_profiles} scope is needed
50+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-self-service-profiles">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-self-service-profiles</a>
51+
* @param selfServiceProfile the self-service profile to create.
52+
* @return a Request to execute.
53+
*/
54+
public Request<SelfServiceProfileResponse> create(SelfServiceProfile selfServiceProfile) {
55+
Asserts.assertNotNull(selfServiceProfile, "self service profile");
56+
Asserts.assertNotNull(selfServiceProfile.getName(), "name");
57+
58+
String url = baseUrl.newBuilder()
59+
.addPathSegments(ORGS_PATH)
60+
.build()
61+
.toString();
62+
63+
BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<SelfServiceProfileResponse>() {
64+
});
65+
request.setBody(selfServiceProfile);
66+
return request;
67+
}
68+
69+
/**
70+
* Request the self-service profile with the given ID.
71+
* A token with {@code read:self_service_profiles} scope is needed
72+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles-by-id</a>
73+
* @param id the self-service profile ID.
74+
* @return a Request to execute.
75+
*/
76+
public Request<SelfServiceProfileResponse> getById(String id) {
77+
Asserts.assertNotNull(id, "id");
78+
79+
String url = baseUrl.newBuilder()
80+
.addPathSegments(ORGS_PATH)
81+
.addPathSegment(id)
82+
.build()
83+
.toString();
84+
85+
return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponse>() {
86+
});
87+
}
88+
89+
/**
90+
* Delete the self-service profile with the given ID.
91+
* A token with {@code delete:self_service_profiles} scope is needed
92+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/delete-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/delete-self-service-profiles-by-id</a>
93+
* @param id the self-service profile ID.
94+
* @return a Request to execute.
95+
*/
96+
public Request<Void> delete(String id) {
97+
Asserts.assertNotNull(id, "id");
98+
99+
String url = baseUrl.newBuilder()
100+
.addPathSegments(ORGS_PATH)
101+
.addPathSegment(id)
102+
.build()
103+
.toString();
104+
105+
return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE);
106+
}
107+
108+
/**
109+
* Update the self-service profile with the given ID.
110+
* A token with {@code update:self_service_profiles} scope is needed
111+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/patch-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/patch-self-service-profiles-by-id</a>
112+
* @param selfServiceProfile the self-service profile to update.
113+
* @param id the self-service profile ID.
114+
* @return a Request to execute.
115+
*/
116+
public Request<SelfServiceProfileResponse> update(SelfServiceProfile selfServiceProfile, String id) {
117+
Asserts.assertNotNull(selfServiceProfile, "self service profile");
118+
Asserts.assertNotNull(id, "id");
119+
120+
String url = baseUrl.newBuilder()
121+
.addPathSegments(ORGS_PATH)
122+
.addPathSegment(id)
123+
.build()
124+
.toString();
125+
126+
BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<SelfServiceProfileResponse>() {
127+
});
128+
request.setBody(selfServiceProfile);
129+
return request;
130+
}
131+
132+
/**
133+
* Get the custom text for specific self-service profile and language.
134+
* A token with {@code read:self_service_profile_custom_texts} scope is needed
135+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profile-custom-text">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profile-custom-text</a>
136+
* @param id the self-service profile ID.
137+
* @param language the language.
138+
* @param page the page.
139+
* @return a Request to execute.
140+
*/
141+
public Request<Object> getCustomText(String id, String language, String page) {
142+
Asserts.assertNotNull(id, "id");
143+
Asserts.assertNotNull(language, "language");
144+
Asserts.assertNotNull(page, "page");
145+
146+
HttpUrl.Builder builder = baseUrl.newBuilder()
147+
.addPathSegments(ORGS_PATH)
148+
.addPathSegment(id)
149+
.addPathSegment("custom-text")
150+
.addPathSegment(language)
151+
.addPathSegment(page);
152+
153+
String url = builder.build().toString();
154+
155+
return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() {
156+
});
157+
}
158+
159+
/**
160+
* Set the custom text for specific self-service profile and language.
161+
* A token with {@code update:self_service_profile_custom_texts} scope is needed
162+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/put-self-service-profile-custom-text">https://auth0.com/docs/api/management/v2#!/self-service-profiles/put-self-service-profile-custom-text</a>
163+
* @param id the self-service profile ID.
164+
* @param language the language.
165+
* @param page the page.
166+
* @param customText the custom text.
167+
* @return a Request to execute.
168+
*/
169+
public Request<Object> setCustomText(String id, String language, String page, Object customText) {
170+
Asserts.assertNotNull(id, "id");
171+
Asserts.assertNotNull(language, "language");
172+
Asserts.assertNotNull(page, "page");
173+
Asserts.assertNotNull(customText, "custom text");
174+
175+
HttpUrl.Builder builder = baseUrl.newBuilder()
176+
.addPathSegments(ORGS_PATH)
177+
.addPathSegment(id)
178+
.addPathSegment("custom-text")
179+
.addPathSegment(language)
180+
.addPathSegment(page);
181+
182+
String url = builder.build().toString();
183+
184+
BaseRequest<Object> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Object>() {
185+
});
186+
request.setBody(customText);
187+
return request;
188+
}
189+
190+
/**
191+
* Create a new SSO access ticket.
192+
* A token with {@code create:sso_access_tickets} scope is needed
193+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-sso-ticket">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-sso-ticket</a>
194+
* @param id the self-service profile ID.
195+
* @param payload the payload.
196+
* @return a Request to execute.
197+
*/
198+
public Request<SsoAccessTicketResponse> createSsoAccessTicket(String id, Object payload) {
199+
Asserts.assertNotNull(id, "id");
200+
Asserts.assertNotNull(payload, "payload");
201+
202+
HttpUrl.Builder builder = baseUrl.newBuilder()
203+
.addPathSegments(ORGS_PATH)
204+
.addPathSegment(id)
205+
.addPathSegment("sso-ticket");
206+
207+
String url = builder.build().toString();
208+
209+
BaseRequest<SsoAccessTicketResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<SsoAccessTicketResponse>() {
210+
});
211+
request.setBody(payload);
212+
return request;
213+
}
214+
215+
/**
216+
* Revoke an SSO ticket.
217+
* A token with {@code delete:sso_access_tickets} scope is needed
218+
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-revoke">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-revoke</a>
219+
* @param id the self-service profile ID.
220+
* @param ticketId the ticket ID.
221+
* @return a Request to execute.
222+
*/
223+
public Request<Void> revokeSsoTicket(String id, String ticketId) {
224+
Asserts.assertNotNull(id, "id");
225+
Asserts.assertNotNull(ticketId, "ticket id");
226+
227+
HttpUrl.Builder builder = baseUrl.newBuilder()
228+
.addPathSegments(ORGS_PATH)
229+
.addPathSegment(id)
230+
.addPathSegment("sso-ticket")
231+
.addPathSegment(ticketId)
232+
.addPathSegment("revoke");
233+
234+
String url = builder.build().toString();
235+
236+
return new EmptyBodyVoidRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Void>() {
237+
});
238+
}
239+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.auth0.client.mgmt.filter;
2+
3+
/**
4+
* Class that represents a filter to be used when requesting a list of items with pagination.
5+
*/
6+
public class PageBasedPaginationFilter extends BaseFilter{
7+
8+
/**
9+
* Filter by page
10+
*
11+
* @param pageNumber the page number to retrieve.
12+
* @param amountPerPage the amount of items per page to retrieve.
13+
* @return this filter instance
14+
*/
15+
public PageBasedPaginationFilter withPage(int pageNumber, int amountPerPage) {
16+
parameters.put("page", pageNumber);
17+
parameters.put("per_page", amountPerPage);
18+
return this;
19+
}
20+
21+
/**
22+
* Include the query summary
23+
*
24+
* @param includeTotals whether to include or not the query summary.
25+
* @return this filter instance
26+
*/
27+
public PageBasedPaginationFilter withTotals(boolean includeTotals) {
28+
parameters.put("include_totals", includeTotals);
29+
return this;
30+
}
31+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.auth0.json.mgmt.selfserviceprofiles;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
@JsonInclude(JsonInclude.Include.NON_NULL)
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class Branding {
10+
@JsonProperty("logo_url")
11+
private String logoUrl;
12+
@JsonProperty("colors")
13+
private Color colors;
14+
15+
/**
16+
* Getter for the logo URL.
17+
* @return the logo URL.
18+
*/
19+
public String getLogoUrl() {
20+
return logoUrl;
21+
}
22+
23+
/**
24+
* Setter for the logo URL.
25+
* @param logoUrl the logo URL to set.
26+
*/
27+
public void setLogoUrl(String logoUrl) {
28+
this.logoUrl = logoUrl;
29+
}
30+
31+
/**
32+
* Getter for the colors.
33+
* @return the colors.
34+
*/
35+
public Color getColors() {
36+
return colors;
37+
}
38+
39+
/**
40+
* Setter for the colors.
41+
* @param colors the colors to set.
42+
*/
43+
public void setColors(Color colors) {
44+
this.colors = colors;
45+
}
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.auth0.json.mgmt.selfserviceprofiles;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
@JsonInclude(JsonInclude.Include.NON_NULL)
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class Color {
11+
@JsonProperty("primary")
12+
private String primary;
13+
14+
/**
15+
* Creates a new instance of the Color class.
16+
*/
17+
public Color() {}
18+
19+
/**
20+
* Creates a new instance of the Color class.
21+
* @param primary the primary color.
22+
*/
23+
@JsonCreator
24+
public Color(@JsonProperty("primary") String primary) {
25+
this.primary = primary;
26+
}
27+
28+
/**
29+
* Getter for the primary color.
30+
* @return the primary color.
31+
*/
32+
public String getPrimary() {
33+
return primary;
34+
}
35+
36+
/**
37+
* Setter for the primary color.
38+
* @param primary the primary color to set.
39+
*/
40+
public void setPrimary(String primary) {
41+
this.primary = primary;
42+
}
43+
}

0 commit comments

Comments
 (0)