Skip to content

Commit db5a1d6

Browse files
committed
Only display user name if we have one
1 parent 7fb156d commit db5a1d6

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/libsync/creds/idtoken.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <QJsonArray>
1818

19+
using namespace Qt::Literals::StringLiterals;
20+
1921
using namespace OCC;
2022

2123
IdToken::IdToken() { }
@@ -27,7 +29,7 @@ IdToken::IdToken(const QJsonObject &payload)
2729

2830
QVariantList IdToken::aud() const
2931
{
30-
const auto aud = _payload.value(QLatin1String("aud"));
32+
const auto aud = _payload.value("aud"_L1);
3133
if (aud.isArray()) {
3234
return aud.toArray().toVariantList();
3335
}
@@ -36,12 +38,17 @@ QVariantList IdToken::aud() const
3638

3739
QString IdToken::sub() const
3840
{
39-
return _payload.value(QLatin1String("sub")).toString();
41+
return _payload.value("sub"_L1).toString();
4042
}
4143

4244
QString IdToken::preferred_username() const
4345
{
44-
return _payload.value(QLatin1String("preferred_username")).toString();
46+
return _payload.value("preferred_username"_L1).toString();
47+
}
48+
49+
QString IdToken::name() const
50+
{
51+
return _payload.value("name"_L1).toString();
4552
}
4653

4754
bool IdToken::isValid() const

src/libsync/creds/idtoken.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class IdToken
2828
QString sub() const;
2929

3030
QString preferred_username() const;
31+
QString name() const;
3132

3233
bool isValid() const;
3334

src/libsync/creds/oauth.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)