[java-idp-plugin-oidc-rp] branch main updated: JOIDCRP-85 - PKCE Code Challenge Method Plain Allowed When OP Supports S256
Codeberg
noreply at shibboleth.net
Thu Nov 19 16:42:05 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-idp-plugin-oidc-rp.
View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-oidc-rp/commit/b77ae0c1f5e1d83fb7fba277c9f831e28f414ddf
The following commit(s) were added to refs/heads/main by this push:
new b77ae0c JOIDCRP-85 - PKCE Code Challenge Method Plain Allowed When OP Supports S256
b77ae0c is described below
commit b77ae0c1f5e1d83fb7fba277c9f831e28f414ddf
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Nov 19 16:37:15 2026 +0000
JOIDCRP-85 - PKCE Code Challenge Method Plain Allowed When OP Supports
S256
- PLAIN would only ever be used if the deployer allowed it in profile
config and the OP only supports PLAIN.
https://shibboleth.atlassian.net/browse/JOIDCRP-85
---
.../impl/AddPCKECodeVerifierAndChallenge.java | 24 +++++++++++++++++++---
.../impl/AddPCKECodeVerifierAndChallengeTest.java | 21 +++++++++++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallenge.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallenge.java
index 12ce4fd..e83d24f 100644
--- a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallenge.java
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallenge.java
@@ -18,6 +18,7 @@ package net.shibboleth.idp.plugin.authn.oidc.rp.messaging.impl;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import java.util.List;
import javax.annotation.Nonnull;
@@ -49,9 +50,26 @@ public class AddPCKECodeVerifierAndChallenge extends AbstractOIDCAuthenticationR
log.trace("{} PKCE enabled, adding code_challenge to request", getLogPrefix());
- final CodeChallengeMethod method =
- getProfileConfiguration().isAllowPKCEPlain(lookupProfileRequestContext(messageContext))
- ? CodeChallengeMethod.PLAIN : CodeChallengeMethod.S256;
+ final List<com.nimbusds.oauth2.sdk.pkce.CodeChallengeMethod> supportedMethods =
+ getProviderMetadata().getCodeChallengeMethods();
+
+ log.trace("{} Provider supports '{}' PKCE code challenge methods", getLogPrefix(), supportedMethods);
+
+ // Default, always use S256 because as a client we can.
+ CodeChallengeMethod method = CodeChallengeMethod.S256;
+
+ final boolean supportsS256 =
+ supportedMethods == null ? false:
+ supportedMethods.contains(com.nimbusds.oauth2.sdk.pkce.CodeChallengeMethod.S256);
+ final boolean supportsPlain =
+ supportedMethods == null ? false:
+ supportedMethods.contains(com.nimbusds.oauth2.sdk.pkce.CodeChallengeMethod.PLAIN);
+
+ // Only switch to PLAIN if allowPlain is true and the OP allows it.
+ if ((supportsPlain && !supportsS256) &&
+ getProfileConfiguration().isAllowPKCEPlain(lookupProfileRequestContext(messageContext))) {
+ method = CodeChallengeMethod.PLAIN;
+ }
final String codeVerifier = generateCodeVerifier(32);
final String challenge = computeCodeChallenge(codeVerifier, method);
diff --git a/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallengeTest.java b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallengeTest.java
index b097bd4..2288c76 100644
--- a/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallengeTest.java
+++ b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddPCKECodeVerifierAndChallengeTest.java
@@ -18,9 +18,13 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
+import java.util.List;
+
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.nimbusds.oauth2.sdk.pkce.CodeChallengeMethod;
+
import net.shibboleth.idp.plugin.authn.oidc.rp.impl.AbstractOIDCTest;
/**
@@ -48,6 +52,7 @@ public class AddPCKECodeVerifierAndChallengeTest extends AbstractOIDCTest {
assertNotNull(authnRequest.getCodeVerifier());
assertNotNull(authnRequest.getCodeChallenge());
+ assertEquals(authnRequest.getCodeChallengeMethod().getValue(), CodeChallengeMethod.S256.getValue());
}
@Test
@@ -66,6 +71,7 @@ public class AddPCKECodeVerifierAndChallengeTest extends AbstractOIDCTest {
public void testSuccessPlain() throws Exception {
partyConfig.setForcePKCE(true);
partyConfig.setAllowPKCEPlain(true);
+ providerCtx.getProviderInformation().setCodeChallengeMethods(List.of(CodeChallengeMethod.PLAIN));
handler.initialize();
final var outboundMsgCtx = getOutboundMessageContextFailIfNull(prc);
handler.invoke(outboundMsgCtx);
@@ -73,6 +79,21 @@ public class AddPCKECodeVerifierAndChallengeTest extends AbstractOIDCTest {
assertNotNull(authnRequest.getCodeVerifier());
assertNotNull(authnRequest.getCodeChallenge());
assertEquals(authnRequest.getCodeVerifier(), authnRequest.getCodeChallenge());
+ assertEquals(authnRequest.getCodeChallengeMethod().getValue(), CodeChallengeMethod.PLAIN.getValue());
+ }
+
+ @Test
+ public void testSuccessS256_WhenPlain_ButPlainNotAllowed() throws Exception {
+ partyConfig.setForcePKCE(true);
+ partyConfig.setAllowPKCEPlain(false);
+ providerCtx.getProviderInformation().setCodeChallengeMethods(List.of(CodeChallengeMethod.PLAIN));
+ handler.initialize();
+ final var outboundMsgCtx = getOutboundMessageContextFailIfNull(prc);
+ handler.invoke(outboundMsgCtx);
+
+ assertNotNull(authnRequest.getCodeVerifier());
+ assertNotNull(authnRequest.getCodeChallenge());
+ assertEquals(authnRequest.getCodeChallengeMethod().getValue(), CodeChallengeMethod.S256.getValue());
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list