Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1606 - added support of PKCE for OAuth2 #1611

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ public static class OAuth2Provider {
private Set<String> adminPrincipals;
private String organizationName;
private String allowedDomain;
private Boolean pkce;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.opendatadiscovery.oddplatform.auth;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;

public final class ODDOAuth2PropertiesConverter {

Expand All @@ -14,11 +16,19 @@ public static OAuth2ClientProperties convertOddProperties(final ODDOAuth2Propert
properties.getClient().forEach((key, provider) -> {
final OAuth2ClientProperties.Registration registration = new OAuth2ClientProperties.Registration();
registration.setClientId(provider.getClientId());
registration.setClientSecret(provider.getClientSecret());

if (BooleanUtils.isTrue(provider.getPkce()) && StringUtils.isBlank(provider.getClientSecret())) {
registration.setClientAuthenticationMethod(ClientAuthenticationMethod.NONE.getValue());
} else {
registration.setClientSecret(provider.getClientSecret());
}

if (StringUtils.isNotEmpty(provider.getClientName())) {
registration.setClientName(provider.getClientName());
}

registration.setScope(provider.getScope());

if (StringUtils.isNotEmpty(provider.getRedirectUri())) {
registration.setRedirectUri(provider.getRedirectUri());
}
Expand Down
1 change: 1 addition & 0 deletions odd-platform-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ auth:
# user-name-attribute:
# admin-attribute:
# admin-principals:
# pkce:
# azure:
# provider: 'azure'
# client-id:
Expand Down
Loading