From 1a7600e356bb0fd903c854d5ec19fdd168ffa31a Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 5 Jan 2021 14:59:59 +0100 Subject: [PATCH] KEYCLOAK-13923 Support PKCE for OIDC based Identity Providers (#7381) * KEYCLOAK-13923 - Support PKCE for Identity Provider We now support usage of PKCE for OIDC based Identity Providers. * KEYCLOAK-13923 Warn if PKCE information cannot be found code-to-token request in OIDCIdentityProvider * KEYCLOAK-13923 Pull up PKCE handling from OIDC to OAuth IdentityProvider infrastructure * KEYCLOAK-13923 Adding test for PKCE support for OAuth Identity providers * KEYCLOAK-13923 Use URI from KeycloakContext instead of HttpRequest Co-authored-by: Pedro Igor Co-authored-by: Pedro Igor --- .../oidc/AbstractOAuth2IdentityProvider.java | 62 +++++++++++++++++++ .../oidc/KeycloakOIDCIdentityProvider.java | 4 -- .../oidc/OAuth2IdentityProviderConfig.java | 30 +++++++++ .../broker/oidc/OIDCIdentityProvider.java | 11 +++- .../oidc/OIDCIdentityProviderConfig.java | 7 ++- .../oidc/endpoints/TokenEndpoint.java | 14 +---- .../protocol/oidc/utils/PkceUtils.java | 54 ++++++++++++++++ .../broker/KcOidcBrokerPkceTest.java | 23 +++++++ .../messages/admin-messages_en.properties | 6 ++ .../realm-identity-provider-oidc.html | 23 ++++++- 10 files changed, 213 insertions(+), 21 deletions(-) create mode 100644 services/src/main/java/org/keycloak/protocol/oidc/utils/PkceUtils.java create mode 100644 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/KcOidcBrokerPkceTest.java diff --git a/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java b/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java index fafd7afccd..bb5365bc64 100755 --- a/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java +++ b/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java @@ -19,6 +19,7 @@ package org.keycloak.broker.oidc; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.jboss.logging.Logger; +import org.jboss.resteasy.spi.HttpRequest; import org.keycloak.OAuth2Constants; import org.keycloak.OAuthErrorException; import org.keycloak.broker.provider.AbstractIdentityProvider; @@ -28,6 +29,7 @@ import org.keycloak.broker.provider.ExchangeExternalToken; import org.keycloak.broker.provider.ExchangeTokenToIdentityProviderToken; import org.keycloak.broker.provider.IdentityBrokerException; import org.keycloak.broker.provider.IdentityProvider; +import org.keycloak.broker.provider.util.IdentityBrokerState; import org.keycloak.broker.provider.util.SimpleHttp; import org.keycloak.common.ClientConnection; import org.keycloak.common.util.Time; @@ -51,11 +53,13 @@ import org.keycloak.models.UserSessionModel; import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.protocol.oidc.OIDCLoginProtocol; import org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint; +import org.keycloak.protocol.oidc.utils.PkceUtils; import org.keycloak.representations.AccessTokenResponse; import org.keycloak.representations.JsonWebToken; import org.keycloak.services.ErrorPage; import org.keycloak.services.ErrorResponseException; import org.keycloak.services.Urls; +import org.keycloak.services.managers.ClientSessionCode; import org.keycloak.services.messages.Messages; import org.keycloak.sessions.AuthenticationSessionModel; import org.keycloak.vault.VaultStringSecret; @@ -103,6 +107,9 @@ public abstract class AbstractOAuth2IdentityProvider
- +
@@ -291,6 +291,27 @@
+
+ +
+ +
+ {{:: 'identity-provider.pkce-enabled.tooltip' | translate}} +
+ +
+ +
+
+ +
+
+ {{:: 'pkce-method.tooltip' | translate}} +
+