8000 Add DPoP support to keycloak-js by sundayScoop · Pull Request #253 · keycloak/keycloak-js · GitHub
[go: up one dir, main page]

Skip to content

Add DPoP support to keycloak-js - #253

Merged
jonkoops merged 10 commits into
keycloak:mainfrom
tide-foundation:dpop-support
Oct 2, 2026
Merged

jonkoops merged 10 commits into
keycloak:mainfrom
tide-foundation:dpop-support

Conversation

@sundayScoop
@sundayScoop sundayScoop commented Jan 30, 2026 •
Copy link
Copy Markdown
Contributor

Add Demonstration of Proof-of-Possession (DPoP) token support as per the RFC, addressing issue #8.

Key Changes

  • Generate and manage public/private key pairs for each client session using IndexedDB unextractable keys
  • Create DPoP proof tokens if required by authorization server (on access/refresh token requests) or resource server
  • Added the secureFetch() wrapper so developers don't have to deal with DPoP flow management (e.g. new nonce provided)
  • Added comprehensive tests covering DPoP functionality

Testing

  • Added tests for DPoP token flows in dpop.spec.ts
  • All existing tests continue to pass

Notes

  • Section 10 was not implemented. This is due to it being OPTIONAL as stated in the RFC and its minimal security benefits.
  • RSA Algorithms were not added as supported key algorithms. Only Elliptical and Edwards curve algorithms were added.

Enabling DPoP Example

await keycloak.init({
    flow: 'implicit',
    useDPoP: { mode: 'auto' }
})

Closes #8

@sundayScoop
sundayScoop force-pushed the dpop-support branch 3 times, most recently from 5cc24c1 to eb42d36 Compare February 5, 2026 05:16
@keycloak keycloak deleted a comment from williamjaackson Feb 17, 2026
@mposolda mposolda self-assigned this Feb 18, 2026
@mposolda
mposolda requested a review from jonkoops February 18, 2026 15:45
@mposolda
Copy link
Copy Markdown
Contributor

@jonkoops Do you please have opportunity to review? I will try to review as well, but feedback from you would be welcome if you have a chance!

@jonkoops
Copy link
Copy Markdown
Contributor

Yes, I will take a look and review. Currently looking at the last bugs for 26.2 that I want to resolve, after that I am going to start merging in features and deprecations for 26.3.

@edewit edewit 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.

👍

@edewit
edewit commented Feb 27, 2026
Copy link
Copy Markdown
Contributor

@sundayScoop can you fix the lint errors though

@sundayScoop
Copy link
Copy Markdown
Contributor Author

@edewit just fixed the lint errors, let me know if there's anything else needed

@edewit
edewit commented Mar 2, 2026
Copy link
Copy Markdown
Contributor

👍

@mposolda
mposolda requested a review from graziang March 3, 2026 10:49
graziang
graziang previously approved these changes Mar 4, 2026
@graziang graziang 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.

@sundayScoop Thanks, from a DPoP RFC point of view, it’s ok for me. I’ll leave to the others a more js-focused review.

@mposolda
mposolda commented Mar 6, 2026
Copy link
Copy Markdown
Contributor

@jonkoops Can you please reply here if you have a chance to review in the near future? Otherwise going to merge this without your review.

@graziang Thanks for your review!

@sundayScoop Thanks again for the PR! We may need also documentation for this feature in the keycloak.js documentation . See this directory https://github.com/keycloak/keycloak-js/tree/main/docs . Probably worth to introduce dedicated section about DPoP and document it here? Besides configuration options, it will be good to document:

  • Fact that crypto API needs to be available. It may be good to document also when it is typically available. I am thinking like a warning with something like DPoP requires Web Crypto API to be available in your browser. The availability of this API may be specific to the particular browser and browser version. The API is typically available just when https is used - I am not sure here, but you probably know more what typical limitations is....
  • It seems the PR supports just ES* and EdDSA algorithms. Is it correct? If yes, it will be also good to document

@jonkoops
jonkoops commented Mar 9, 2026
Copy link
Copy Markdown
Contributor

Please hold off on merging this PR until we have done a final patch release. I intend to merge this in for 26.3.0, together with some other work for a feature release.

@sundayScoop
sundayScoop commented Mar 10, 2026 •
Copy link
Copy Markdown
Contributor Author

@jonkoops Can you please reply here if you have a chance to review in the near future? Otherwise going to merge this without your review.

@graziang Thanks for your review!

@sundayScoop Thanks again for the PR! We may need also documentation for this feature in the keycloak.js documentation . See this directory https://github.com/keycloak/keycloak-js/tree/main/docs . Probably worth to introduce dedicated section about DPoP and document it here? Besides configuration options, it will be good to document:

  • Fact that crypto API needs to be available. It may be good to document also when it is typically available. I am thinking like a warning with something like DPoP requires Web Crypto API to be available in your browser. The availability of this API may be specific to the particular browser and browser version. The API is typically available just when https is used - I am not sure here, but you probably know more what typical limitations is....
  • It seems the PR supports just ES* and EdDSA algorithms. Is it correct? If yes, it will be also good to document

@mposolda regarding the crypto API suggestion - there is this check in keycloak-dpop.js:

if (typeof crypto === 'undefined' || !crypto.subtle) {
  throw new Error('DPoP requires Web Crypto API (crypto.subtle) which is not available in this environment.')
}

Were you thinking of explicitly showing a warning message to the user without an error? Or just improving the message in the error being thrown? I realise there's no mention of the https requirement in the error, so that might be good to add.

Aside from that I've just finished the requested docs - so nearly there!

@jonkoops
Copy link
Copy Markdown
Contributor

We already have places where we detect the Crypto API and throw if it is not found:

keycloak-js/lib/keycloak.js

Lines 1623 to 1625 in fa52139

if (typeof crypto === 'undefined' || typeof crypto.randomUUID === 'undefined') {
throw new Error('Web Crypto API is not available.')
}

keycloak-js/lib/keycloak.js

Lines 1689 to 1691 in fa52139

if (typeof crypto === 'undefined' || typeof crypto.getRandomValues === 'undefined') {
throw new Error('Web Crypto API is not available.')
}

keycloak-js/lib/keycloak.js

Lines 1946 to 1948 in fa52139

if (typeof crypto === 'undefined' || typeof crypto.subtle === 'undefined') {
throw new Error('Web Crypto API is not available.')
}

Keycloak JS relies on the Web Crypto API, and therefore only works in a secure context. Perhaps we can roll up this feature detection into a single utility function that is called in all the places where the API is called, to reduce repetition.

@mposolda
Copy link
Copy Markdown
Contributor

@jonkoops Can you please reply here if you have a chance to review in the near future? Otherwise going to merge this without your review.
@graziang Thanks for your review!
@sundayScoop Thanks again for the PR! We may need also documentation for this feature in the keycloak.js documentation . See this directory https://github.com/keycloak/keycloak-js/tree/main/docs . Probably worth to introduce dedicated section about DPoP and document it here? Besides configuration options, it will be good to document:

  • Fact that crypto API needs to be available. It may be good to document also when it is typically available. I am thinking like a warning with something like DPoP requires Web Crypto API to be available in your browser. The availability of this API may be specific to the particular browser and browser version. The API is typically available just when https is used - I am not sure here, but you probably know more what typical limitations is....
  • It seems the PR supports just ES* and EdDSA algorithms. Is it correct? If yes, it will be also good to document

@mposolda regarding the crypto API suggestion - there is this check in keycloak-dpop.js:

if (typeof crypto === 'undefined' || !crypto.subtle) {
  throw new Error('DPoP requires Web Crypto API (crypto.subtle) which is not available in this environment.')
}

Were you thinking of explicitly showing a warning message to the user without an error? Or just improving the message in the error being thrown? I realise there's no mention of the https requirement in the error, so that might be good to add.

Aside from that I've just finished the requested docs - so nearly there!

@sundayScoop I was concerned just about documentation here. It can be good to explicitly mention in the keycloak.js documentation that DPoP would be available just if Crypto API is available. And use some warning/formulation in the docs about this similar to what I've mentioned.

For example see some warning in the current keycloak.js documentation https://www.keycloak.org/securing-apps/javascript-adapter#_using_the_adapter (The warning in this section about "Silent check-sso functionality is limited in some modern browsers." )

@mposolda
Copy link
Copy Markdown
Contributor

Please hold off on merging this PR until we have done a final patch release. I intend to merge this in for 26.3.0, together with some other work for a feature release.

@jonkoops Cool, Thanks! Any ETA when it could be merged approximately? And when you plan 26.3.0 release?

@jonkoops
Copy link
Copy Markdown
Contributor

@jonkoops Cool, Thanks! Any ETA when it could be merged approximately? And when you plan 26.3.0 release?

At most in a couple of weeks. I am currently rather busy with my talk for BackstageCon, so my bandwidth is limited.

@sundayScoop
Copy link
Copy Markdown
Contributor Author

@mposolda just added the requested docs. Sorry for the delay - had quite a busy few weeks.

Let me know what you think of the docs

@mposolda
Copy link
Copy Markdown
Contributor

@jonkoops Cool, Thanks! Any ETA when it could be merged approximately? And when you plan 26.3.0 release?

At most in a couple of weeks. I am currently rather busy with my talk for BackstageCon, so my bandwidth is limited.

@jonkoops Thanks for the update

mposolda
mposolda previously approved these changes Mar 23, 2026
@mposolda mposolda 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.

@sundayScoop Thanks for the documentation! I am approving this PR from my point of view. The merge might be delayed though (See comments above from @jonkoops ), but hopefully we would be able to do it in few weeks

Update: There is the issue in Build guides . Are you able to take a look?

@mposolda
mposolda self-requested a review March 23, 2026 08:59
@sundayScoop
Copy link
Copy Markdown
Contributor Author

Looking now

@jonkoops
Copy link
Copy Markdown
Contributor

Created #329 to discuss the v27 readiness. So we don't further pollute this PR with unrelated chatter.

@mposolda mposolda mentioned this pull request Aug 11, 2026
@mposolda
Copy link
Copy Markdown
Contributor

@jonkoops Sorry, but that did not answered my question from the comment #253 (comment) :-)

Could you please share here or in that issue #329 what do you see as next steps to make it finally possible to merge this PR?

@jonkoops jonkoops 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.

Preliminary review, some comments I already prepped a while ago, but never got around to finishing my review.

Comment thread lib/keycloak.d.ts Outdated
/**
* Enables DPoP token auth flows and session key generation.
*/
useDPoP?: DPoPConfig
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.

I'd rather not call an option that provides a config useX, as this implies a boolean value. Ideally this would be something like dpopConfig.

Suggested change
useDPoP?: DPoPConfig
dpopConfig?: DPoPConfig

Comment thread lib/keycloak.js Outdated
}
}

secureFetch = async (url, init = {}) => {
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.

This method is not annotated with JSDOC types like other functions, which is causing some type errors in IDEs. We're trying to add types wherever we can, so that this code can be easily converted to pure TypeScript at a later point.

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.

Also it would be better to just call it fetch as then it will then be keycloak.fetch

@sundayScoop
Copy link
Copy Markdown
Contributor Author

Thanks for taking the time to review my work guys! I'll look at it tomorrow so we can get this in ASAP

@edewit
edewit commented Sep 29, 2026
Copy link
Copy Markdown
Contributor

I've fixed the DCO sign-offs on my commits (they were missing Signed-off-by). The branch with the corrected history is:

https://github.com/edewit/keycloak-js/tree/fix/pr-253-dco

Tree content is unchanged — only commit messages were updated to add sign-off on my four commits.

@sundayScoop could you please update dpop-support with that history? Maintainers can't push to this fork (maintainer_can_modify is false). For example:

git fetch https://github.com/edewit/keycloak-js.git fix/pr-253-dco
git checkout dpop-support
git reset --hard FETCH_HEAD
git push --force-with-lease origin dpop-support

That should clear the DCO check. Thanks!

@jonkoops
jonkoops commented Oct 2, 2026
Copy link
Copy Markdown
Contributor

@sundayScoop @edewit could you rebase this branch on main, there are some merge conflicts.

sundayScoop and others added 9 commits October 2, 2026 09:46
Closes keycloak#8

Signed-off-by: sundayScoop <killer.of.time@protonmail.com>

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Consolidate identical access/refresh token DPoP fetch paths, extract shared nonce validation and secureFetch proof building, and add reusable DPoP test helpers with parameterized algorithm tests.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Flush and re-initialize DPoP keys in clearToken() to match logout behavior, expose strictStorage on useDPoP config, and add a test verifying key rotation after clearToken.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Aligns the public API with review feedback: init option is dpopConfig and the DPoP-aware HTTP helper is keycloak.fetch().

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Closes keycloak#8

Signed-off-by: sundayScoop <killer.of.time@protonmail.com>

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: sundayScoop <killer.of.time@protonmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: sundayScoop <killer.of.time@protonmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: sundayScoop <killer.of.time@protonmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
@jonkoops
jonkoops enabled auto-merge (squash) October 2, 2026 08:48
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
auto-merge was automatically disabled October 2, 2026 10:09

Head branch was pushed to by a user without write access

@jonkoops
jonkoops merged commit 8803e6b into keycloak:main Oct 2, 2026
4 checks passed
@yahorsi
yahorsi commented Oct 2, 2026
Copy link
Copy Markdown

When it could be released?

@jonkoops
Copy link
Copy Markdown
Contributor

If it were up to me, ASAP. But unfortunately, @pskopek is the only one who can do releases.

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.

DPoP support in keycloak.js

6 participants

FF
0