Skip to content

Commit a80953a

Browse files
Cosmin Cojocarjricher
authored andcommitted
Allow both flows authorization code and client credentials. This scenario might be found when the same client supports user authentication as well as service to service authentication. Such a client is trusted (whitelisted).
1 parent dce80d4 commit a80953a

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

openid-connect-server/src/main/java/org/mitre/openid/connect/web/DynamicClientRegistrationEndpoint.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,11 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
394394
// set default grant types if needed
395395
if (newClient.getGrantTypes() == null || newClient.getGrantTypes().isEmpty()) {
396396
if (newClient.getScope().contains("offline_access")) { // client asked for offline access
397-
newClient.setGrantTypes(Sets.newHashSet("authorization_code", "refresh_token")); // allow authorization code and refresh token grant types by default
397+
// allow authorization code, client credentials and refresh token grant types by default
398+
newClient.setGrantTypes(Sets.newHashSet("authorization_code", "client_credentials", "refresh_token"));
398399
} else {
399-
newClient.setGrantTypes(Sets.newHashSet("authorization_code")); // allow authorization code grant type by default
400+
// allow authorization code grant type by default
401+
newClient.setGrantTypes(Sets.newHashSet("authorization_code", "client_credentials"));
400402
}
401403
}
402404

@@ -418,8 +420,7 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
418420
if (newClient.getGrantTypes().contains("authorization_code")) {
419421

420422
// check for incompatible grants
421-
if (newClient.getGrantTypes().contains("implicit") ||
422-
newClient.getGrantTypes().contains("client_credentials")) {
423+
if (newClient.getGrantTypes().contains("implicit")) {
423424
// return an error, you can't have these grant types together
424425
throw new ValidationException("invalid_client_metadata", "Incompatible grant types requested: " + newClient.getGrantTypes(), HttpStatus.BAD_REQUEST);
425426
}
@@ -430,15 +431,12 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
430431
}
431432

432433
newClient.getResponseTypes().add("code");
433-
434-
435434
}
436435

437436
if (newClient.getGrantTypes().contains("implicit")) {
438437

439438
// check for incompatible grants
440-
if (newClient.getGrantTypes().contains("authorization_code") ||
441-
newClient.getGrantTypes().contains("client_credentials")) {
439+
if (newClient.getGrantTypes().contains("authorization_code")) {
442440
// return an error, you can't have these grant types together
443441
throw new ValidationException("invalid_client_metadata", "Incompatible grant types requested: " + newClient.getGrantTypes(), HttpStatus.BAD_REQUEST);
444442
}
@@ -456,14 +454,7 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
456454
}
457455

458456
if (newClient.getGrantTypes().contains("client_credentials")) {
459-
460-
// check for incompatible grants
461-
if (newClient.getGrantTypes().contains("authorization_code") ||
462-
newClient.getGrantTypes().contains("implicit")) {
463-
// return an error, you can't have these grant types together
464-
throw new ValidationException("invalid_client_metadata", "Incompatible grant types requested: " + newClient.getGrantTypes(), HttpStatus.BAD_REQUEST);
465-
}
466-
457+
467458
if (!newClient.getResponseTypes().isEmpty()) {
468459
// return an error, you can't have this grant type and response type together
469460
throw new ValidationException("invalid_client_metadata", "Incompatible response types requested: " + newClient.getGrantTypes() + " / " + newClient.getResponseTypes(), HttpStatus.BAD_REQUEST);

0 commit comments

Comments
 (0)