Skip to content

providers/oauth2: OpenID key binding support - #22590

Merged
BeryJu merged 33 commits into
goauthentik:mainfrom
EthanHeilman:kb
Jul 16, 2026
Merged

BeryJu merged 33 commits into
goauthentik:mainfrom
EthanHeilman:kb

Conversation

@EthanHeilman

@EthanHeilman EthanHeilman commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Details

This PR adds OpenID Key Binding to authentik. OpenID Key Binding binds a public key to an ID Token using mechanisms defined in RFC9449, OAuth 2.0 Demonstrating Proof of Possession (DPoP). For more details see the draft OpenID spec for Key Binding https://openid.github.io/connect-key-binding/main.html

We add key binding support for the authorization code, device code and refresh flows fully supporting all flows specified in the draft standard. The draft standard does not key bind the access token and we follow that here.

The PR contains:

  • The code implementing the key binding feature
    • Adds key_bound scope to list of scopes
    • Adds new ID Token typ dpop+id_token
    • Mitigation to add new field dpop_jkt to authorizationcode, devicetoken and refreshtoken models. This is needed to remember the public key bound to token for each of those flows.
    • Stores jti claims in the authentik cache to protect against replay attacks
  • Unit tests

Currently this doesn't make any changes to docs since it doesn't seem there is a doc per flow type in the docs directory, but if docs for this feature is desired, I do have some I could can add.


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema and clients have been updated (make gen)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make docs)

Appendix

These are largely for my own notes to document my design decisions. Feel free to read, but not required to understand to review the PR.

Replay protection and JTI

Following the recommendation given in RFC 9449 Token Replay, we use the jti claim in the DPOP proof to detect replayed DPoP proofs:

In the context of the target URI, servers can store the jti value of each DPoP proof for the time window in which the respective DPoP proof JWT would be accepted to prevent multiple uses of the same DPoP proof. HTTP requests to the same URI for which the jti value has been seen before would be declined.

To do this we employ authentiks caching mechanism to store these proofs for 3 minutes. Any proof older or newer than 60 seconds is considered expired and rejected. We enforce a max JTI string size of 256 characters

An assumption we make here is that the cache is shared between all instances of authentik or all instances of authentik at an URI. If this was not the case, would be possible a DPoP proof can be replayed. Preventing replay is not a requirement of DPoP with the standard stating:

When strictly enforced, such a single-use check provides a very strong protection against DPoP proof replay, but it may not always be feasible in practice, e.g., when multiple servers behind a single endpoint have no shared state.

JTI or (JTI AND HTU)

When strictly enforced, such a single-use check provides a very strong protection against DPoP proof replay, but it may not always be feasible in practice, e.g., when multiple servers behind a single endpoint have no shared state.

We check only uniqueness of the jti in the cache. It would be allowed by the standard to store the jti and the htu (URI of the request) in the cache and then only reject if the pair (jti, htu) was not unique. We choose to check uniqueness of jti and not the pair (jti, htu) to "fail faster" and make finding bugs easier. If someone is using a non-unique jti we want them to get errors early so they can fix it in testing. Using the htu might hide a non-random jti bug.

Is JTI strictly needed here?

We support three flows: authorization code, device code and refresh flow. The authorization code and the device code flows use the hash of the auth_code or the device code as the claim c_s256 in the DPoP proof functioning like a nonce. This should prevent DPoP replays and makes the jti check in these flows unnecessary. Only the refresh flow has a security benefit from the jti check. So why not skip the jti check for the authorization code and device code?

  • The jti check is recommended by standard and expected. If a developer noticed that the jti check is not happening, they might assume this is a security bug and report it. Better to do the expected thing to reduce false positives.
  • Skipping the check would not simplify the code and would require special casing for different flows.
  • Checking the jti allows the dpop code added in this PR to be used for dpop as authentik adopts dpop more generally.

@netlify

netlify Bot commented May 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 133cf6e
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a58b2d0d0512a0008ea6b84
😎 Deploy Preview https://deploy-preview-22590--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 0c1db24
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a5853a9725c3e00071fe060
😎 Deploy Preview https://deploy-preview-22590--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 133cf6e
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a58b2d01f660100076bb1d9
😎 Deploy Preview https://deploy-preview-22590--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@BeryJu BeryJu changed the title feat: OpenID key binding support providers/oauth2: OpenID key binding support Jun 1, 2026
@codecov

codecov Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.57085% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (bfcc21f) to head (133cf6e).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
authentik/providers/oauth2/tests/test_dpop.py 96.44% 9 Missing ⚠️
authentik/providers/oauth2/dpop.py 95.65% 6 Missing ⚠️
authentik/providers/oauth2/views/token.py 95.91% 2 Missing ⚠️
authentik/providers/oauth2/views/authorize.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #22590      +/-   ##
==========================================
+ Coverage   92.61%   92.79%   +0.17%     
==========================================
  Files        1051     1056       +5     
  Lines       61983    62716     +733     
  Branches      424      424              
==========================================
+ Hits        57408    58196     +788     
+ Misses       4575     4520      -55     
Flag Coverage Δ
conformance 35.56% <11.60%> (-0.30%) ⬇️
e2e 40.61% <11.60%> (+0.18%) ⬆️
integration 31.54% <8.36%> (-0.77%) ⬇️
rust 0.00% <ø> (ø)
unit 92.00% <97.57%> (+0.11%) ⬆️
unit-migrate 92.02% <97.57%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@EthanHeilman
EthanHeilman marked this pull request as ready for review June 16, 2026 20:13
@EthanHeilman
EthanHeilman requested a review from a team as a code owner June 16, 2026 20:13

@gergosimonyi gergosimonyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems clean, thank you for the contribution!

I'll leave it to @BeryJu to merge

@BeryJu
BeryJu enabled auto-merge (squash) July 16, 2026 10:30
@BeryJu
BeryJu merged commit 428bd7d into goauthentik:main Jul 16, 2026
116 checks passed
kensternberg-authentik added a commit that referenced this pull request Jul 18, 2026
…int/ak-progress

* web/typo/enterprise-status-card-properties: (41 commits)
  The language between licensed and isLicensed was confusing, so internally the progressBar expression uses 'allowed' for the number of licensed users, and 'licensed' for the overall state of the product.
  The severities ought to be in order, otherwise it's a mental pause.
  Another typo.
  Noticed a typo; prettier had an opinion.
  web/maint: clean-up ak-enterprise-status-card
  Some revisions to the enterprise status card.
  policies: make policy bindings expire-able (#24116)
  enterprise/endpoints/connectors/fleet: pass populate_policies (#24108)
  lifecycle/container: drop curl and runit (#24008)
  lib: move ExpiringModel to lib from core (#24109)
  web, docs, packages/*: Fix pnpm Workspace Catalogs (#23944)
  providers/oauth2: OpenID key binding support (#22590)
  core: bump github.com/go-ldap/ldap/v3 from 3.4.13 to 3.4.14 (#24088)
  core: bump uvicorn[standard] from 0.50.2 to 0.51.0 (#24089)
  core: bump coverage[toml] from 7.15.0 to 7.15.1 (#24090)
  core: bump uuid from 1.23.4 to 1.23.5 (#24091)
  core: bump json-subscriber from 0.2.8 to 0.3.0 (#24092)
  ci: bump softprops/action-gh-release from 3.0.1 to 3.0.2 (#24093)
  ci: bump actions/setup-node from 6.4.0 to 7.0.0 (#24094)
  ci: bump actions/setup-node from 6.4.0 to 7.0.0 in /.github/actions/setup (#24096)
  ...
wim07101993 added a commit to zitadel/oidc that referenced this pull request Sep 14, 2026
# Which Problems Are Solved

This PR adds client support for [OpenID Key Binding
1.0](https://openid.net/specs/openid-connect-key-binding-1_0.html) a
draft standard for Proof-of-Possession ID Tokens. Basically ID Tokens
that have a public key enabling the user to sign under their identity.

OpenPubkey supports key binding using zitadel/oidc as the library.
However because zitadel/oidc does not natively support key binding,
OpenPubkey has to use [a fragile rounder-tripper work around for the
RP](https://github.com/openpubkey/openpubkey/blob/main/providers/keybinding_provider.go#L109).

This PR allows key binding support for OP and RP:
- Authorization code flow
- Device code flow
- Refresh flow
- Unit tests

This PR is only for client/RP. It does not add key binding to the OP
code. I would like to add that at a future point, but client/RP support
the main blocker to using plain zitadel/oidc with key binding.

I've run manual tests for code flow, refresh and device flow using the
key binding with the Hello OP and this PR in OpenPubkey that runs
against this branch: openpubkey/openpubkey#395

# How the Problems Are Solved

Adds a `WithKeyBinding` option to RP so that the RP can request key
bound ID Tokens from the OP and a `KeyBindingRelyingParty` to perform
the additional steps used by key binding.

```golang
func WithKeyBinding(signer crypto.Signer, alg jose.SignatureAlgorithm) Option
```

# Additional Changes

No additional changes

# Additional Context

Do you want me to port this to v4 as well as v3?

Relevant PRs
- PR adding Key Binding to Authentik
goauthentik/authentik#22590
- [OpenID Key Binding 1.0 Latest
Draft](https://openid.net/specs/openid-connect-key-binding-1_0.html)
- PR to use this RP option in OpenPubkey
openpubkey/openpubkey#395

---------

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Wim Van Laer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants