@@ -430,7 +430,7 @@ pub(crate) async fn get(
430
430
. with_code ( "User exists" )
431
431
. with_description ( format ! (
432
432
r"Upstream account provider returned {localpart:?} as username,
433
- which is not linked to that upstream account"
433
+ which is not linked to that upstream account"
434
434
) )
435
435
. with_language ( & locale) ;
436
436
@@ -444,23 +444,32 @@ pub(crate) async fn get(
444
444
. evaluate_upstream_oauth_register ( & localpart, None )
445
445
. await ?;
446
446
447
- if !res. valid ( ) {
447
+ if res. valid ( ) {
448
+ // The username passes the policy check, add it to the context
449
+ ctx. with_localpart (
450
+ localpart,
451
+ provider. claims_imports . localpart . is_forced ( ) ,
452
+ )
453
+ } else if provider. claims_imports . localpart . is_forced ( ) {
454
+ // If the username claim is 'forced' but doesn't pass the policy check,
455
+ // we display an error message.
448
456
// TODO: translate
449
457
let ctx = ErrorContext :: new ( )
450
458
. with_code ( "Policy error" )
451
459
. with_description ( format ! (
452
460
r"Upstream account provider returned {localpart:?} as username,
453
- which does not pass the policy check: {res}"
461
+ which does not pass the policy check: {res}"
454
462
) )
455
463
. with_language ( & locale) ;
456
464
457
465
return Ok ( (
458
466
cookie_jar,
459
467
Html ( templates. render_error ( & ctx) ?) . into_response ( ) ,
460
468
) ) ;
469
+ } else {
470
+ // Else, we just ignore it when it doesn't pass the policy check.
471
+ ctx
461
472
}
462
-
463
- ctx. with_localpart ( localpart, provider. claims_imports . localpart . is_forced ( ) )
464
473
}
465
474
None => ctx,
466
475
}
0 commit comments