oauth2-proxy fails the login callback while checking the ID token
Your error
Error redeeming code during OAuth2 callback: could not verify id_token: failed to verify token: oidc: id token issued by a different provider, expected "https://..." got "https://..."2 more lines it can showFix it fast
Most common cause, 1 of 3The token's issuer differs from --oidc-issuer-url
Set --oidc-issuer-url to the got value from the log, which must also equal the issuer field of the discovery document, then restart the proxy.
--oidc-issuer-url=https://<keycloak-host>/realms/<realm>
# Entra ID multi-tenant app (config file form)
oidc_issuer_url = "https://login.microsoftonline.com/common/v2.0"
insecure_oidc_skip_issuer_verification = true
entra_id_allowed_tenants = ["<tenant-id>"]Short answer
Error redeeming code during OAuth2 callback: could not verify id_token means oauth2-proxy refused the ID token your OpenID Connect provider returned. The words after it name the check: a different issuer (copy the token's iss into --oidc-issuer-url), an invalid audience (add an audience mapper or --oidc-extra-audience) or an expired token (fix the clock). oauth2-proxy 7.15.
Which cause do you have?
Pull the whole error line from the proxy's log. The phrase after could not verify id_token tells you which check failed, and each phrase matches one cause below.
kubectl logs deployment/oauth2-proxy | grep "could not verify id_token"
# not on Kubernetes: search the log of the service or container that runs the proxyThen find the line you see in this list and open its fix:
- 1The token's issuer differs from --oidc-issuer-url
oidc: id token issued by a different provider, expected "..." got "..." - 2The aud claim does not contain your client ID
invalid audience: audience from claim aud with value [...], and the browser shows a 403 page - 3The clock on the proxy host is wrong
oidc: token is expired (Token Expiry: ...) moments after a fresh login, or current time ... before the nbf (not before) time
What does the error look like?
Error redeeming code during OAuth2 callback: could not verify id_token: failed to verify token: oidc: id token issued by a different provider, expected "https://..." got "https://..."Invalid authentication via OAuth2: could not verify id_token: invalid audience: audience from claim aud with value [...] does not match with any of allowed audiences map[...]could not verify id_token: failed to verify token: oidc: token is expired (Token Expiry: ...)
Cause 1 of 3
The token's issuer differs from --oidc-issuer-url
You seeoidc: id token issued by a different provider, expected "..." got "..."
Check
could not verify id_token followed by id token issued by a different provider means the iss claim in the token is not the issuer URL oauth2-proxy was given. go-oidc compares the two as plain strings, so one extra slash, the old Keycloak /auth prefix or a second host name for the same server will fail.
curl -s https://<keycloak-host>/realms/<realm>/.well-known/openid-configuration | jq -r .issuerFix
Set --oidc-issuer-url to the got value from the log, which must also equal the issuer field of the discovery document, then restart the proxy. A multi-tenant Entra ID app is the documented exception: use the common v2.0 URL, turn issuer verification off and list the tenants you accept.
--oidc-issuer-url=https://<keycloak-host>/realms/<realm>
# Entra ID multi-tenant app (config file form)
oidc_issuer_url = "https://login.microsoftonline.com/common/v2.0"
insecure_oidc_skip_issuer_verification = true
entra_id_allowed_tenants = ["<tenant-id>"]Verify
A new login in a private window lands on the upstream app, and the log has no issuer line.
kubectl logs deployment/oauth2-proxy --since=5m | grep -c "different provider"Confirmed by oauth2-proxy.github.io
Cause 2 of 3
The aud claim does not contain your client ID
You seeinvalid audience: audience from claim aud with value [...], and the browser shows a 403 page
Check
When could not verify id_token says invalid audience, no value in the token's aud claim equals --client-id or any --oidc-extra-audience entry. With Keycloak, the client needs an Audience mapper that writes the client name into the ID token. Current releases log this as Invalid authentication via OAuth2 and answer 403.
kubectl logs deployment/oauth2-proxy | grep -o "with value \[[^]]*\]"Fix
In the Keycloak admin console open Clients, your client, Client scopes, then the dedicated scope. Add a mapper of type Audience, pick your client under Included Client Audience and switch Add to ID token on. If the provider must keep another audience, allow that value in oauth2-proxy.
--oidc-extra-audience=<value shown in the aud list>Verify
Log in again: the 403 page is gone and the upstream app loads.
kubectl logs deployment/oauth2-proxy --since=5m | grep -c "invalid audience"Confirmed by oauth2-proxy.github.io
Cause 3 of 3
The clock on the proxy host is wrong
You seeoidc: token is expired (Token Expiry: ...) moments after a fresh login, or current time ... before the nbf (not before) time
Check
An ID token that counts as expired the moment it arrives points to the clock where oauth2-proxy runs. go-oidc compares exp with local time and gives nbf five minutes of leeway, so a clock that runs fast makes new tokens look expired, and one far behind makes them look not yet valid.
timedatectl statusFix
Turn on network time synchronization on that machine or Kubernetes node, wait for the clock to settle, then repeat the login.
sudo timedatectl set-ntp trueVerify
timedatectl status reports network time sync as active and the next login passes.
timedatectl statusConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Copy the issuer value from the provider's .well-known/openid-configuration into the proxy config character for character, never from memory.
- Create the Keycloak Audience mapper in the same realm export or Terraform code that creates the oauth2-proxy client.
- Keep network time sync enabled on every node that can run the proxy pod.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.