@@ -229,6 +229,9 @@ public PKCEAlgorithm deserialize(JsonElement json, Type typeOfT, JsonDeserializa
229
229
public String apiGetAllClients (Model model , Authentication auth ) {
230
230
231
231
Collection <ClientDetailsEntity > clients = clientService .getAllClients ();
232
+
233
+ clients .forEach (client -> client .setClientSecret (null ));
234
+
232
235
model .addAttribute (JsonEntityView .ENTITY , clients );
233
236
234
237
if (AuthenticationUtilities .isAdmin (auth )) {
@@ -320,6 +323,8 @@ public String apiAddClient(@RequestBody String jsonString, Model m, Authenticati
320
323
321
324
try {
322
325
ClientDetailsEntity newClient = clientService .saveNewClient (client );
326
+
327
+ //Set the client secret to the plaintext from the request
323
328
m .addAttribute (JsonEntityView .ENTITY , newClient );
324
329
325
330
if (AuthenticationUtilities .isAdmin (auth )) {
@@ -385,6 +390,7 @@ public String apiUpdateClient(@PathVariable("id") Long id, @RequestBody String j
385
390
}
386
391
387
392
ClientDetailsEntity oldClient = clientService .getClientById (id );
393
+ String plaintextSecret = client .getClientSecret ();
388
394
389
395
if (oldClient == null ) {
390
396
logger .error ("apiUpdateClient failed; client with id " + id + " could not be found." );
@@ -408,10 +414,10 @@ public String apiUpdateClient(@PathVariable("id") Long id, @RequestBody String j
408
414
|| client .getTokenEndpointAuthMethod ().equals (AuthMethod .SECRET_POST )
409
415
|| client .getTokenEndpointAuthMethod ().equals (AuthMethod .SECRET_JWT )) {
410
416
411
- // if they've asked for us to generate a client secret (or they left it blank but require one), do so here
412
- if (json .has ("generateClientSecret" ) && json .get ("generateClientSecret" ).getAsBoolean ()
413
- || Strings .isNullOrEmpty (client .getClientSecret ())) {
417
+ // Once a client has been created, we only update the secret when asked to
418
+ if (json .has ("generateClientSecret" ) && json .get ("generateClientSecret" ).getAsBoolean ()) {
414
419
client = clientService .generateClientSecret (client );
420
+ plaintextSecret = client .getClientSecret ();
415
421
}
416
422
417
423
} else if (client .getTokenEndpointAuthMethod ().equals (AuthMethod .PRIVATE_KEY )) {
@@ -438,6 +444,10 @@ public String apiUpdateClient(@PathVariable("id") Long id, @RequestBody String j
438
444
439
445
try {
440
446
ClientDetailsEntity newClient = clientService .updateClient (oldClient , client );
447
+
448
+ //Set the client secret to the plaintext from the request
449
+ newClient .setClientSecret (plaintextSecret );
450
+
441
451
m .addAttribute (JsonEntityView .ENTITY , newClient );
442
452
443
453
if (AuthenticationUtilities .isAdmin (auth )) {
@@ -497,6 +507,9 @@ public String apiShowClient(@PathVariable("id") Long id, Model model, Authentica
497
507
return JsonErrorView .VIEWNAME ;
498
508
}
499
509
510
+ //We don't want the UI to get the secret
511
+ client .setClientSecret (null );
512
+
500
513
model .addAttribute (JsonEntityView .ENTITY , client );
501
514
502
515
if (AuthenticationUtilities .isAdmin (auth )) {
0 commit comments