Skip to content

feat(openid-connect): add set_raw_id_token_header option - #13616

Merged
nic-6443 merged 3 commits into
apache:masterfrom
luarx:feat/openid-connect-set-enc-id-token-header
Jul 24, 2026
Merged

feat(openid-connect): add set_raw_id_token_header option#13616
nic-6443 merged 3 commits into
apache:masterfrom
luarx:feat/openid-connect-set-enc-id-token-header

Conversation

@luarx

@luarx luarx commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description

Add a new boolean plugin option set_raw_id_token_header (default: false) that, when
enabled, forwards the raw RS256-signed ID token JWT to upstream via the X-Raw-ID-Token
request header.

Unlike the existing X-ID-Token header (which contains base64(JSON(decoded_claims)) with
no cryptographic signature), X-Raw-ID-Token carries the original signed token verifiable
against the identity provider's JWKS endpoint.

Implementation details:

  • The header is cleared at rewrite entry to prevent client injection.
    ensures enc_id_token is included so the raw JWT is persisted in the session by
    lua-resty-openidc. When session_contents is nil (the default), lua-resty-openidc stores all
    session data including enc_id_token, so no action is needed.
  • Only available in the full OIDC session flow (not in the bearer/introspection path, where
    no session exists).

Which issue(s) this PR fixes:

Fixes #13615

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the
    APISIX mailing list first)

Add a new boolean plugin option `set_enc_id_token_header` (default: false)
that, when enabled, forwards the raw RS256-signed ID token JWT to upstream
services via the `X-Enc-ID-Token` request header.

Unlike the existing `X-ID-Token` header (which contains
`base64(JSON(decoded_claims))` with no cryptographic signature),
`X-Enc-ID-Token` carries the original signed token that can be verified
against the identity provider's JWKS endpoint.

Implementation notes:
- The header is cleared at rewrite entry to prevent client injection.
- When the user has explicitly restricted `session_contents`, the plugin
  automatically adds `enc_id_token` to the list so the raw JWT is
  persisted in the session by lua-resty-openidc.
- When `session_contents` is nil (the default), lua-resty-openidc stores
  all session data including `enc_id_token`, so no action is needed.
- The feature is only available in the full OIDC session flow
  (not in the bearer/introspection path, where no session exists).

Closes apache#13615
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jun 26, 2026
Comment thread apisix/plugins/openid-connect.lua Outdated
…d_token_header

X-Enc-ID-Token exposed lua-resty-openidc's internal session key name,
which is unintelligible to gateway users. Rename the option and header
to match the field's actual purpose

@bzp2010 bzp2010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold on a moment.

What does enc mean? What is it an abbreviation for? encrypt?

If so, JWT does not involve encryption. Its payload is always in plaintext; JWT is merely a signature, not encryption. It seems more appropriate to call it raw_id_token.

This corresponds to the stripped id_token currently provided.

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

adding on to what @bzp2010 said, it might be worthwile to make the header name configurable.

@nic-6443 nic-6443 changed the title feat(openid-connect): add set_enc_id_token_header option feat(openid-connect): add set_raw_id_token_header option Jul 23, 2026
@nic-6443

Copy link
Copy Markdown
Member

@bzp2010 The code already uses raw_id_token. The contributor forgot to update the PR title and description.

@shreemaan-abhishek I don't think we need to add configuration options for now. There are already several headers in this plugin without corresponding configuration options. We can add them all together when there is demand.

@luarx

luarx commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

The code already uses raw_id_token. The contributor forgot to update the PR title and description.

That is correct, thanks for changing it 🙏

I don't think we need to add configuration options for now. There are already several headers in this plugin without corresponding configuration options

That's, I basically tried to follow the other header options to maintain consistency.

@nic-6443
nic-6443 merged commit 64cd2df into apache:master Jul 24, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: As a user, I want the openid-connect plugin to expose the raw signed ID token to upstream for JWKS verification

5 participants