@@ -238,6 +238,7 @@ OAuth::OAuth(const QUrl &serverUrl, QNetworkAccessManager *networkAccessManager,
238238 , _networkAccessManager(networkAccessManager)
239239 , _clientId(Theme::instance()->oauthClientId())
240240 , _clientSecret(Theme::instance()->oauthClientSecret())
241+ , _scopes(Theme::instance()->openIdConnectScopes())
241242 , _supportedPromtValues(defaultOauthPromtValue())
242243{
243244}
@@ -434,7 +435,7 @@ QNetworkReply *OAuth::postTokenRequest(QUrlQuery &&queryItems)
434435 req.setHeader (QNetworkRequest::ContentTypeHeader, QStringLiteral (" application/x-www-form-urlencoded; charset=UTF-8" ));
435436 req.setAttribute (HttpCredentials::DontAddCredentialsAttribute, true );
436437
437- queryItems.addQueryItem (QStringLiteral (" scope" ), QString::fromUtf8 (QUrl::toPercentEncoding (Theme::instance ()-> openIdConnectScopes () )));
438+ queryItems.addQueryItem (QStringLiteral (" scope" ), QString::fromUtf8 (QUrl::toPercentEncoding (this -> _scopes )));
438439 req.setUrl (_tokenEndpoint);
439440 return _networkAccessManager->post (req, queryItems.toString (QUrl::FullyEncoded).toUtf8 ());
440441}
@@ -540,8 +541,12 @@ void OAuth::fetchWellKnown()
540541 } else {
541542 QNetworkRequest webfingerReq;
542543 webfingerReq.setAttribute (HttpCredentials::DontAddCredentialsAttribute, true );
543- webfingerReq.setUrl (
544- Utility::concatUrlPath (_serverUrl, QStringLiteral (" /.well-known/webfinger" ), {{QStringLiteral (" resource" ), _serverUrl.toString ()}}));
544+ webfingerReq.setUrl (Utility::concatUrlPath (_serverUrl, QStringLiteral (" /.well-known/webfinger" ),
545+ {
546+ {QStringLiteral (" resource" ), _serverUrl.toString ()},
547+ {QStringLiteral (" rel" ), QStringLiteral (" http://openid.net/specs/connect/1.0/issuer" )},
548+ {QStringLiteral (" platform" ), QStringLiteral (" desktop" )},
549+ }));
545550 webfingerReq.setTransferTimeout (defaultTimeoutMs ());
546551
547552 auto webfingerReply = _networkAccessManager->get (webfingerReq);
@@ -596,6 +601,28 @@ void OAuth::fetchWellKnown()
596601 return ;
597602 }
598603
604+ const auto properties = doc.object ().value (QStringLiteral (" properties" )).toObject ();
605+ if (const auto clientId = properties.value (QStringLiteral (" http://opencloud.eu/ns/oidc/client_id" )).toString (); !clientId.isNull ()) {
606+ this ->_clientId = clientId;
607+ }
608+ if (const auto scopes = properties.value (QStringLiteral (" http://opencloud.eu/ns/oidc/client_id" )).toObject (); !scopes.isEmpty ()) {
609+ auto scopesString = QString ();
610+ for (auto scope : scopes) {
611+ auto s = scope.toString ();
612+ if (s.isNull ()) {
613+ qCWarning (lcOauth) << u" unexpected non-string scope received from WebFinger, ignoring" ;
614+ continue ;
615+ }
616+ if (s.isEmpty ()) {
617+ qCWarning (lcOauth) << u" empty scope received from WebFinger, ignoring" ;
618+ continue ;
619+ }
620+ scopesString.append (s);
621+ scopesString.append (QStringLiteral (" " ));
622+ }
623+ this ->_scopes = scopesString;
624+ }
625+
599626 auto const oidcWellKnownUrl = Utility::concatUrlPath (QUrl (issuerUrl), wellKnownPathC);
600627 qCDebug (lcOauth) << u" fetching" << oidcWellKnownUrl;
601628
0 commit comments