@@ -394,11 +394,14 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
394
394
// set default grant types if needed
395
395
if (newClient .getGrantTypes () == null || newClient .getGrantTypes ().isEmpty ()) {
396
396
if (newClient .getScope ().contains ("offline_access" )) { // client asked for offline access
397
- // allow authorization code, client credentials and refresh token grant types by default
398
- newClient .setGrantTypes (Sets .newHashSet ("authorization_code" , "client_credentials" , "refresh_token" ));
397
+ newClient .setGrantTypes (Sets .newHashSet ("authorization_code" , "refresh_token" )); // allow authorization code and refresh token grant types by default
399
398
} else {
400
- // allow authorization code grant type by default
401
- newClient .setGrantTypes (Sets .newHashSet ("authorization_code" , "client_credentials" ));
399
+ newClient .setGrantTypes (Sets .newHashSet ("authorization_code" )); // allow authorization code grant type by default
400
+ }
401
+ if (config .isDualClient ()) {
402
+ Set <String > extendedGrandTypes = newClient .getGrantTypes ();
403
+ extendedGrandTypes .add ("client_credentials" );
404
+ newClient .setGrantTypes (extendedGrandTypes );
402
405
}
403
406
}
404
407
@@ -420,7 +423,8 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
420
423
if (newClient .getGrantTypes ().contains ("authorization_code" )) {
421
424
422
425
// check for incompatible grants
423
- if (newClient .getGrantTypes ().contains ("implicit" )) {
426
+ if (newClient .getGrantTypes ().contains ("implicit" ) ||
427
+ (!config .isDualClient () && newClient .getGrantTypes ().contains ("client_credentials" ))) {
424
428
// return an error, you can't have these grant types together
425
429
throw new ValidationException ("invalid_client_metadata" , "Incompatible grant types requested: " + newClient .getGrantTypes (), HttpStatus .BAD_REQUEST );
426
430
}
@@ -436,7 +440,8 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
436
440
if (newClient .getGrantTypes ().contains ("implicit" )) {
437
441
438
442
// check for incompatible grants
439
- if (newClient .getGrantTypes ().contains ("authorization_code" )) {
443
+ if (newClient .getGrantTypes ().contains ("authorization_code" ) ||
444
+ (!config .isDualClient () && newClient .getGrantTypes ().contains ("client_credentials" ))) {
440
445
// return an error, you can't have these grant types together
441
446
throw new ValidationException ("invalid_client_metadata" , "Incompatible grant types requested: " + newClient .getGrantTypes (), HttpStatus .BAD_REQUEST );
442
447
}
@@ -454,7 +459,14 @@ private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) th
454
459
}
455
460
456
461
if (newClient .getGrantTypes ().contains ("client_credentials" )) {
457
-
462
+
463
+ // check for incompatible grants
464
+ if (!config .isDualClient () &&
465
+ (newClient .getGrantTypes ().contains ("authorization_code" ) || newClient .getGrantTypes ().contains ("implicit" ))) {
466
+ // return an error, you can't have these grant types together
467
+ throw new ValidationException ("invalid_client_metadata" , "Incompatible grant types requested: " + newClient .getGrantTypes (), HttpStatus .BAD_REQUEST );
468
+ }
469
+
458
470
if (!newClient .getResponseTypes ().isEmpty ()) {
459
471
// return an error, you can't have this grant type and response type together
460
472
throw new ValidationException ("invalid_client_metadata" , "Incompatible response types requested: " + newClient .getGrantTypes () + " / " + newClient .getResponseTypes (), HttpStatus .BAD_REQUEST );
0 commit comments