Connect with Keycloak
Enable PKCE
What is PKCE?
Proof Key for Code Exchange (PKCE) is an extension to the OAuth 2.0 authorization code flow. It is designed to prevent interception of the authorization code by malicious applications. For this reason, PKCE is an OpenID Connect flow that is best suited for mobile and native applications as well as Single Page Applications (SPAs) which cannot securely store a Client Secret.
How does PKCE work?
A unique code verifier is generated for each authorization request. The code verifier is used to generate a code challenge. The code challenge is sent to the authorization server along with the authorization request. The authorization server uses the code challenge to verify the code verifier when the authorization code is exchanged for an access token.
Figure 1. Authorization Code Flow with PKCE
How to enable PKCE in Keycloak?
- In the OpenID Connect settings for the identity provider, ensure that
Use discovery endpoint
is set toOff
. This will allow you to manually configure the OpenID Connect settings. - Switch the
Use PKCE
toggle toOn
. This will enable thePKCE Method
field. - Set the
PKCE Method
toS256
. Note that this setting is recommended (instead ofplain
) for security reasons.