Skip to content

Commit

Permalink
Fix authZ code flow with PKCE (#653)
Browse files Browse the repository at this point in the history
- code_verifier parameter missed in the token request
- code challenge method is configurable
  • Loading branch information
rmiccoli authored Oct 5, 2023
1 parent 3f3cb3e commit 0e80638
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.mitre.oauth2.model.PKCEAlgorithm;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

Expand All @@ -14,6 +15,7 @@ public static class OidcClientProperties {
String clientSecret;
List<String> redirectUris;
String scope;
PKCEAlgorithm codeChallengeMethod;

public String getClientId() {
return clientId;
Expand Down Expand Up @@ -46,6 +48,14 @@ public String getScope() {
public void setScope(String scope) {
this.scope = scope;
}

public PKCEAlgorithm getCodeChallengeMethod() {
return codeChallengeMethod;
}

public void setCodeChallengeMethod(PKCEAlgorithm codeChallengeMethod) {
this.codeChallengeMethod = codeChallengeMethod;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ private MultiValueMap<String, String> initTokenRequestParameters(HttpServletRequ
form.setAll(getAuthRequestOptionsService().getTokenOptions(config.serverConfig,
config.clientConfig, request));

String codeVerifier = getStoredCodeVerifier(request.getSession());
if (codeVerifier != null) {
form.add("code_verifier", codeVerifier);
}

String redirectUri = getStoredSessionString(request.getSession(), REDIRECT_URI_SESION_VARIABLE);

if (redirectUri != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private StaticClientConfigurationService staticClientConfiguration() {
cde.setTokenEndpointAuthMethod(AuthMethod.SECRET_BASIC);
cde.setClientId(iamClientConfig.getClient().getClientId());
cde.setClientSecret(iamClientConfig.getClient().getClientSecret());
cde.setCodeChallengeMethod(iamClientConfig.getClient().getCodeChallengeMethod());

if (Strings.isNotBlank(iamClientConfig.getClient().getScope())) {
cde.setScope(
Expand Down

0 comments on commit 0e80638

Please sign in to comment.