Skip to content

Commit

Permalink
Prompt for required client id parameter when missing in profile. May …
Browse files Browse the repository at this point in the history
…omit the client secret parameter if an empty string.
  • Loading branch information
dkocher committed Jul 3, 2023
1 parent c5fd62f commit f8a18bc
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f8a18bc

Please sign in to comment.