Skip to content

Commit

Permalink
Add support for public clients
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Aug 22, 2024
1 parent 51e8de3 commit 10f0b6b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
31 changes: 21 additions & 10 deletions src/libsync/creds/oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ class RegisterClientJob : public QObject
private:
void registerClientOnline()
{
const QJsonObject json({ { QStringLiteral("client_name"), QStringLiteral("%1 %2").arg(Theme::instance()->appNameGUI(), OCC::Version::versionWithBuildNumber().toString()) },
{ QStringLiteral("redirect_uris"), QJsonArray { QStringLiteral("http://127.0.0.1") } },
{ QStringLiteral("application_type"), QStringLiteral("native") },
{ QStringLiteral("token_endpoint_auth_method"), QStringLiteral("client_secret_basic") } });
const QJsonObject json(
{{QStringLiteral("client_name"), QStringLiteral("%1 %2").arg(Theme::instance()->appNameGUI(), OCC::Version::versionWithBuildNumber().toString())},
{QStringLiteral("redirect_uris"), QJsonArray{QStringLiteral("http://127.0.0.1")}},
{QStringLiteral("application_type"), QStringLiteral("native")}, //
{QStringLiteral("token_endpoint_auth_method"), QStringLiteral("none")}});
QNetworkRequest req;
req.setUrl(_registrationEndpoint);
req.setAttribute(HttpCredentials::DontAddCredentialsAttribute, true);
Expand Down Expand Up @@ -436,6 +437,9 @@ QNetworkReply *OAuth::postTokenRequest(QUrlQuery &&queryItems)
queryItems.addQueryItem(QStringLiteral("client_id"), _clientId);
queryItems.addQueryItem(QStringLiteral("client_secret"), _clientSecret);
break;
case TokenEndpointAuthMethods::none:
queryItems.addQueryItem(QStringLiteral("client_id"), _clientId);
break;
}
req.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded; charset=UTF-8"));
req.setAttribute(HttpCredentials::DontAddCredentialsAttribute, true);
Expand Down Expand Up @@ -554,13 +558,20 @@ void OAuth::fetchWellKnown()
_registrationEndpoint = QUrl::fromEncoded(data[QStringLiteral("registration_endpoint")].toString().toUtf8());
_redirectUrl = QStringLiteral("http://127.0.0.1");

const auto authMethods = data.value(QStringLiteral("token_endpoint_auth_methods_supported")).toArray();
if (authMethods.contains(QStringLiteral("client_secret_basic"))) {
_endpointAuthMethod = TokenEndpointAuthMethods::client_secret_basic;
} else if (authMethods.contains(QStringLiteral("client_secret_post"))) {
_endpointAuthMethod = TokenEndpointAuthMethods::client_secret_post;
if (_clientSecret.isEmpty()) {
_endpointAuthMethod = TokenEndpointAuthMethods::none;
} else {
OC_ASSERT_X(false, qPrintable(QStringLiteral("Unsupported token_endpoint_auth_methods_supported: %1").arg(QDebug::toString(authMethods))));
const auto authMethods = data.value(QStringLiteral("token_endpoint_auth_methods_supported")).toArray();
if (authMethods.contains(QStringLiteral("none"))) {
_endpointAuthMethod = TokenEndpointAuthMethods::none;
} else if (authMethods.contains(QStringLiteral("client_secret_post"))) {
_endpointAuthMethod = TokenEndpointAuthMethods::client_secret_post;
} else if (authMethods.contains(QStringLiteral("client_secret_basic"))) {
_endpointAuthMethod = TokenEndpointAuthMethods::client_secret_basic;
} else {
OC_ASSERT_X(
false, qPrintable(QStringLiteral("Unsupported token_endpoint_auth_methods_supported: %1").arg(QDebug::toString(authMethods))));
}
}
const auto promtValuesSupported = data.value(QStringLiteral("prompt_values_supported")).toArray();
if (!promtValuesSupported.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/creds/oauth.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class OWNCLOUDSYNC_EXPORT OAuth : public QObject
public:
enum Result { NotSupported, LoggedIn, Error, ErrorInsecureUrl };
Q_ENUM(Result)
enum class TokenEndpointAuthMethods : char { client_secret_basic, client_secret_post };
enum class TokenEndpointAuthMethods : char { none, client_secret_basic, client_secret_post };
Q_ENUM(TokenEndpointAuthMethods)

enum class PromptValuesSupported : char { none = 0, consent = 1 << 0, select_account = 1 << 1 };
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@ QString Theme::quotaBaseFolder() const

QString Theme::oauthClientId() const
{
return QStringLiteral("xdXOt13JKxym1B1QcEncf2XDkLAexMBFwiT9j6EfhhHFJhs2KM9jbjTmf8JBXE69");
return QStringLiteral("ownCloud Desktop Client 6.0+");
}

QString Theme::oauthClientSecret() const
{
return QStringLiteral("UBntmLjC2yYCeHwsyj73Uwo9TAaecAetRwMw0xYcvNL9yRdLSUi0hUAHfvCHFeFh");
return QString();
}

QString Theme::oauthLocalhost() const
Expand Down

0 comments on commit 10f0b6b

Please sign in to comment.