@@ -394,9 +394,11 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
394394// set default grant types if needed
395395if (newClient .getGrantTypes () == null || newClient .getGrantTypes ().isEmpty ()) {
396396if (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
418420if (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
424425throw 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
432433newClient .getResponseTypes ().add ("code" );
433-
434-
435434}
436435
437436if (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
443441throw 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
458456if (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+
467458if (!newClient .getResponseTypes ().isEmpty ()) {
468459// return an error, you can't have this grant type and response type together
469460throw new ValidationException ("invalid_client_metadata" , "Incompatible response types requested: " + newClient .getGrantTypes () + " / " + newClient .getResponseTypes (), HttpStatus .BAD_REQUEST );
0 commit comments