@@ -374,12 +374,21 @@ void OAuth::startAuthentication()
374374 reportError (tr (" The audience of the id_token did not contain \" %1\" " ).arg (_clientId));
375375 } else if (_idToken.isValid () && _idToken.sub () != idToken.sub ()) {
376376 // Connected with the wrong user
377- qCWarning (lcOauth) << " We expected the user" << _idToken.preferred_username () << " but the server answered with user"
378- << idToken.preferred_username ();
379- const QString message = tr (" <h1>Incorrect user</h1>"
380- " <p>You logged-in with user <em>%1</em>, but must login with user <em>%2</em>.<br>"
381- " Please return to the %3 and restart the authentication.</p>" )
382- .arg (idToken.preferred_username (), _idToken.preferred_username (), Theme::instance ()->appNameGUI ());
377+ qCWarning (lcOauth) << " We expected the user" << _idToken.toJson () << " but the server answered with user" << idToken.toJson ();
378+ const QString expectedName = !_idToken.preferred_username ().isEmpty () ? _idToken.preferred_username () : _idToken.name ();
379+ const QString actualName = !idToken.preferred_username ().isEmpty () ? idToken.preferred_username () : idToken.name ();
380+ QString message;
381+ if (!expectedName.isEmpty () && !actualName.isEmpty ()) {
382+ message = tr (" <h1>Incorrect user</h1>"
383+ " <p>You logged-in as user <em>%1</em>, but must login with user <em>%2</em>.<br>"
384+ " Please return to the %3 and restart the authentication.</p>" )
385+ .arg (actualName, expectedName, Theme::instance ()->appNameGUI ());
386+ } else {
387+ message = tr (" <h1>Incorrect user</h1>"
388+ " <p>You logged-in as a different user than is associated with this account.<br>"
389+ " Please return to the %1 and restart the authentication.</p>" )
390+ .arg (Theme::instance ()->appNameGUI ());
391+ }
383392 httpReplyAndClose (socket, QStringLiteral (" 403 Forbidden" ), tr (" Incorrect user" ), message);
384393 Q_EMIT result (Error);
385394 } else {
0 commit comments