From f8a18bcbf5540044747ab05b01eeae181d3ddcc7 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Mon, 3 Jul 2023 10:24:07 +0200 Subject: [PATCH] Prompt for required client id parameter when missing in profile. May omit the client secret parameter if an empty string. --- .../oauth/OAuth2AuthorizationService.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/oauth/src/main/java/ch/cyberduck/core/oauth/OAuth2AuthorizationService.java b/oauth/src/main/java/ch/cyberduck/core/oauth/OAuth2AuthorizationService.java index c43e0fe7bcd..25eae92e0be 100644 --- a/oauth/src/main/java/ch/cyberduck/core/oauth/OAuth2AuthorizationService.java +++ b/oauth/src/main/java/ch/cyberduck/core/oauth/OAuth2AuthorizationService.java @@ -31,6 +31,7 @@ import ch.cyberduck.core.exception.LoginFailureException; import ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService; import ch.cyberduck.core.http.UserAgentHttpRequestInitializer; +import ch.cyberduck.core.preferences.HostPreferences; import ch.cyberduck.core.preferences.PreferencesFactory; import ch.cyberduck.core.threading.CancelCallback; @@ -165,11 +166,32 @@ private TokenResponse authorizeWithCode(final Host bookmark, final LoginCallback ); } // Start OAuth2 flow within browser + final ClientParametersAuthentication clientParameters; + if(StringUtils.isBlank(clientid)) { + if(null != new HostPreferences(bookmark).getProperty("oauth.clientid")) { + clientParameters = new ClientParametersAuthentication(new HostPreferences(bookmark).getProperty("oauth.clientid"), StringUtils.EMPTY); + } + else { + final Credentials clientid = prompt.prompt(bookmark, + LocaleFactory.localizedString("OAuth Client ID", "Credentials"), + LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), + new LoginOptions(bookmark.getProtocol()) + .user(true).password(true) + .passwordPlaceholder("OAuth Client ID")); + if(clientid.isSaved()) { + bookmark.setProperty("oauth.clientid", clientid.getPassword()); + } + clientParameters = new ClientParametersAuthentication(clientid.getUsername(), StringUtils.EMPTY); + } + } + else { + clientParameters = new ClientParametersAuthentication(clientid, clientsecret); + } final AuthorizationCodeFlow.Builder flowBuilder = new AuthorizationCodeFlow.Builder( method, transport, json, new GenericUrl(tokenServerUrl), - new ClientParametersAuthentication(clientid, clientsecret), + clientParameters, clientid, authorizationServerUrl) .setScopes(scopes)