Skip to content

Commit af1239e

Browse files
committed
client library sync
1 parent 36495f4 commit af1239e

21 files changed

+734
-23
lines changed

src/main/java/io/fusionauth/client/FusionAuthClient.java

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import io.fusionauth.domain.OpenIdConfiguration;
3939
import io.fusionauth.domain.api.APIKeyRequest;
4040
import io.fusionauth.domain.api.APIKeyResponse;
41+
import io.fusionauth.domain.api.ApplicationOAuthScopeRequest;
42+
import io.fusionauth.domain.api.ApplicationOAuthScopeResponse;
4143
import io.fusionauth.domain.api.ApplicationRequest;
4244
import io.fusionauth.domain.api.ApplicationResponse;
4345
import io.fusionauth.domain.api.ApplicationSearchRequest;
@@ -904,6 +906,26 @@ public ClientResponse<MessengerResponse, Errors> createMessenger(UUID messengerI
904906
.go();
905907
}
906908

909+
/**
910+
* Creates a new custom OAuth scope for an application. You must specify the Id of the application you are creating the scope for.
911+
* You can optionally specify an Id for the OAuth scope on the URL, if not provided one will be generated.
912+
*
913+
* @param applicationId The Id of the application to create the OAuth scope on.
914+
* @param scopeId (Optional) The Id of the OAuth scope. If not provided a secure random UUID will be generated.
915+
* @param request The request object that contains all the information used to create the OAuth OAuth scope.
916+
* @return The ClientResponse object.
917+
*/
918+
public ClientResponse<ApplicationOAuthScopeResponse, Errors> createOAuthScope(UUID applicationId, UUID scopeId, ApplicationOAuthScopeRequest request) {
919+
return start(ApplicationOAuthScopeResponse.class, Errors.class)
920+
.uri("/api/application")
921+
.urlSegment(applicationId)
922+
.urlSegment("scope")
923+
.urlSegment(scopeId)
924+
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
925+
.post()
926+
.go();
927+
}
928+
907929
/**
908930
* Creates a tenant. You can optionally specify an Id for the tenant, if not provided one will be generated.
909931
*
@@ -1156,7 +1178,7 @@ public ClientResponse<Void, Errors> deleteApplication(UUID applicationId) {
11561178
* Hard deletes an application role. This is a dangerous operation and should not be used in most circumstances. This
11571179
* permanently removes the given role from all users that had it.
11581180
*
1159-
* @param applicationId The Id of the application to deactivate.
1181+
* @param applicationId The Id of the application that the role belongs to.
11601182
* @param roleId The Id of the role to delete.
11611183
* @return The ClientResponse object.
11621184
*/
@@ -1417,6 +1439,24 @@ public ClientResponse<Void, Errors> deleteMessenger(UUID messengerId) {
14171439
.go();
14181440
}
14191441

1442+
/**
1443+
* Hard deletes a custom OAuth scope.
1444+
* OAuth workflows that are still requesting the deleted OAuth scope may fail depending on the application's unknown scope policy.
1445+
*
1446+
* @param applicationId The Id of the application that the OAuth scope belongs to.
1447+
* @param scopeId The Id of the OAuth scope to delete.
1448+
* @return The ClientResponse object.
1449+
*/
1450+
public ClientResponse<Void, Errors> deleteOAuthScope(UUID applicationId, UUID scopeId) {
1451+
return start(Void.TYPE, Errors.class)
1452+
.uri("/api/application")
1453+
.urlSegment(applicationId)
1454+
.urlSegment("scope")
1455+
.urlSegment(scopeId)
1456+
.delete()
1457+
.go();
1458+
}
1459+
14201460
/**
14211461
* Deletes the user registration for the given user and application.
14221462
*
@@ -2431,6 +2471,25 @@ public ClientResponse<MessengerResponse, Errors> patchMessenger(UUID messengerId
24312471
.go();
24322472
}
24332473

2474+
/**
2475+
* Updates, via PATCH, the custom OAuth scope with the given Id for the application.
2476+
*
2477+
* @param applicationId The Id of the application that the OAuth scope belongs to.
2478+
* @param scopeId The Id of the OAuth scope to update.
2479+
* @param request The request that contains just the new OAuth scope information.
2480+
* @return The ClientResponse object.
2481+
*/
2482+
public ClientResponse<ApplicationOAuthScopeResponse, Errors> patchOAuthScope(UUID applicationId, UUID scopeId, Map<String, Object> request) {
2483+
return start(ApplicationOAuthScopeResponse.class, Errors.class)
2484+
.uri("/api/application")
2485+
.urlSegment(applicationId)
2486+
.urlSegment("scope")
2487+
.urlSegment(scopeId)
2488+
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
2489+
.patch()
2490+
.go();
2491+
}
2492+
24342493
/**
24352494
* Updates, via PATCH, the registration for the user with the given Id and the application defined in the request.
24362495
*
@@ -3497,6 +3556,23 @@ public ClientResponse<MonthlyActiveUserReportResponse, Errors> retrieveMonthlyAc
34973556
.go();
34983557
}
34993558

3559+
/**
3560+
* Retrieves a custom OAuth scope.
3561+
*
3562+
* @param applicationId The Id of the application that the OAuth scope belongs to.
3563+
* @param scopeId The Id of the OAuth scope to retrieve.
3564+
* @return The ClientResponse object.
3565+
*/
3566+
public ClientResponse<ApplicationOAuthScopeResponse, Errors> retrieveOAuthScope(UUID applicationId, UUID scopeId) {
3567+
return start(ApplicationOAuthScopeResponse.class, Errors.class)
3568+
.uri("/api/application")
3569+
.urlSegment(applicationId)
3570+
.urlSegment("scope")
3571+
.urlSegment(scopeId)
3572+
.get()
3573+
.go();
3574+
}
3575+
35003576
/**
35013577
* Retrieves the Oauth2 configuration for the application for the given Application Id.
35023578
*
@@ -5229,6 +5305,25 @@ public ClientResponse<MessengerResponse, Errors> updateMessenger(UUID messengerI
52295305
.go();
52305306
}
52315307

5308+
/**
5309+
* Updates the OAuth scope with the given Id for the application.
5310+
*
5311+
* @param applicationId The Id of the application that the OAuth scope belongs to.
5312+
* @param scopeId The Id of the OAuth scope to update.
5313+
* @param request The request that contains all the new OAuth scope information.
5314+
* @return The ClientResponse object.
5315+
*/
5316+
public ClientResponse<ApplicationOAuthScopeResponse, Errors> updateOAuthScope(UUID applicationId, UUID scopeId, ApplicationOAuthScopeRequest request) {
5317+
return start(ApplicationOAuthScopeResponse.class, Errors.class)
5318+
.uri("/api/application")
5319+
.urlSegment(applicationId)
5320+
.urlSegment("scope")
5321+
.urlSegment(scopeId)
5322+
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
5323+
.put()
5324+
.go();
5325+
}
5326+
52325327
/**
52335328
* Updates the registration for the user with the given Id and the application defined in the request.
52345329
*

src/main/java/io/fusionauth/domain/Application.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
/*
2-
* Copyright (c) 2019-2023, FusionAuth, All Rights Reserved
2+
* Copyright (c) 2019-2024, FusionAuth, All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing,
11+
* software distributed under the License is distributed on an
12+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
* either express or implied. See the License for the specific
14+
* language governing permissions and limitations under the License.
315
*/
416
package io.fusionauth.domain;
517

@@ -82,6 +94,10 @@ public class Application implements Buildable<Application>, Tenantable {
8294

8395
public SAMLv2Configuration samlv2Configuration = new SAMLv2Configuration();
8496

97+
// Do not include the application Id for individual scopes when returning as part of the full application
98+
@JsonIgnoreProperties("applicationId")
99+
public List<ApplicationOAuthScope> scopes = new ArrayList<>();
100+
85101
public ObjectState state;
86102

87103
public UUID tenantId;
@@ -127,6 +143,7 @@ public Application(Application other) {
127143
this.registrationDeletePolicy = new ApplicationRegistrationDeletePolicy(other.registrationDeletePolicy);
128144
this.roles.addAll(other.roles.stream().map(ApplicationRole::new).collect(Collectors.toList()));
129145
this.samlv2Configuration = new SAMLv2Configuration(other.samlv2Configuration);
146+
this.scopes.addAll(other.scopes.stream().map(ApplicationOAuthScope::new).collect(Collectors.toList()));
130147
this.state = other.state;
131148
this.tenantId = other.tenantId;
132149
this.themeId = other.themeId;
@@ -192,6 +209,7 @@ public boolean equals(Object o) {
192209
Objects.equals(registrationDeletePolicy, that.registrationDeletePolicy) &&
193210
Objects.equals(roles, that.roles) &&
194211
Objects.equals(samlv2Configuration, that.samlv2Configuration) &&
212+
Objects.equals(scopes, that.scopes) &&
195213
state == that.state &&
196214
Objects.equals(tenantId, that.tenantId) &&
197215
Objects.equals(themeId, that.themeId) &&
@@ -210,6 +228,12 @@ public void setActive(boolean active) {
210228
state = active ? ObjectState.Active : ObjectState.Inactive;
211229
}
212230

231+
public ApplicationOAuthScope getOAuthScope(String name) {
232+
return scopes.stream()
233+
.filter(s -> s.name.equals(name))
234+
.findFirst().orElse(null);
235+
}
236+
213237
public ApplicationRole getRole(String name) {
214238
for (ApplicationRole role : roles) {
215239
if (role.name.equals(name)) {
@@ -232,7 +256,7 @@ public boolean hasDefaultRole() {
232256
@Override
233257
public int hashCode() {
234258
// active is omitted
235-
return Objects.hash(accessControlConfiguration, authenticationTokenConfiguration, cleanSpeakConfiguration, data, emailConfiguration, externalIdentifierConfiguration, formConfiguration, id, insertInstant, jwtConfiguration, lambdaConfiguration, lastUpdateInstant, loginConfiguration, multiFactorConfiguration, name, oauthConfiguration, passwordlessConfiguration, registrationConfiguration, registrationDeletePolicy, roles, samlv2Configuration, state, tenantId, themeId, unverified, verificationEmailTemplateId, verificationStrategy, verifyRegistration, webAuthnConfiguration);
259+
return Objects.hash(accessControlConfiguration, authenticationTokenConfiguration, cleanSpeakConfiguration, data, emailConfiguration, externalIdentifierConfiguration, formConfiguration, id, insertInstant, jwtConfiguration, lambdaConfiguration, lastUpdateInstant, loginConfiguration, multiFactorConfiguration, name, oauthConfiguration, passwordlessConfiguration, registrationConfiguration, registrationDeletePolicy, roles, samlv2Configuration, scopes, state, tenantId, themeId, unverified, verificationEmailTemplateId, verificationStrategy, verifyRegistration, webAuthnConfiguration);
236260
}
237261

238262
public void normalize() {
@@ -251,6 +275,8 @@ public void normalize() {
251275

252276
roles.forEach(ApplicationRole::normalize);
253277

278+
scopes.forEach(ApplicationOAuthScope::normalize);
279+
254280
if (multiFactorConfiguration.loginPolicy == null) {
255281
multiFactorConfiguration.trustPolicy = null;
256282
}
@@ -264,6 +290,11 @@ public Application secure() {
264290
return this;
265291
}
266292

293+
public Application sortOAuthScopes() {
294+
scopes.sort(ApplicationOAuthScope::compareTo);
295+
return this;
296+
}
297+
267298
public Application sortRoles() {
268299
roles.sort(ApplicationRole::compareTo);
269300
return this;
@@ -419,6 +450,8 @@ public static class LambdaConfiguration {
419450

420451
public UUID selfServiceRegistrationValidationId;
421452

453+
public UUID userinfoPopulateId;
454+
422455
@JacksonConstructor
423456
public LambdaConfiguration() {
424457
}
@@ -428,6 +461,7 @@ public LambdaConfiguration(LambdaConfiguration other) {
428461
this.idTokenPopulateId = other.idTokenPopulateId;
429462
this.samlv2PopulateId = other.samlv2PopulateId;
430463
this.selfServiceRegistrationValidationId = other.selfServiceRegistrationValidationId;
464+
this.userinfoPopulateId = other.userinfoPopulateId;
431465
}
432466

433467
@Override
@@ -442,12 +476,13 @@ public boolean equals(Object o) {
442476
return Objects.equals(accessTokenPopulateId, that.accessTokenPopulateId) &&
443477
Objects.equals(idTokenPopulateId, that.idTokenPopulateId) &&
444478
Objects.equals(samlv2PopulateId, that.samlv2PopulateId) &&
445-
Objects.equals(selfServiceRegistrationValidationId, that.selfServiceRegistrationValidationId);
479+
Objects.equals(selfServiceRegistrationValidationId, that.selfServiceRegistrationValidationId) &&
480+
Objects.equals(userinfoPopulateId, that.userinfoPopulateId);
446481
}
447482

448483
@Override
449484
public int hashCode() {
450-
return Objects.hash(accessTokenPopulateId, idTokenPopulateId, samlv2PopulateId, selfServiceRegistrationValidationId);
485+
return Objects.hash(accessTokenPopulateId, idTokenPopulateId, samlv2PopulateId, selfServiceRegistrationValidationId, userinfoPopulateId);
451486
}
452487

453488
@Override

0 commit comments

Comments
 (0)