8000 [OID4VCI] Generate pre-authorized codes using the JWT format by IngridPuppet · Pull Request #46450 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

[OID4VCI] Generate pre-authorized codes using the JWT format - #46450

Merged
mposolda merged 2 commits into
keycloak:mainfrom
adorsys:45231-pre-auth-codes-as-jwts
Mar 25, 2026
Merged

mposolda merged 2 commits into
keycloak:mainfrom
adorsys:45231-pre-auth-codes-as-jwts

Conversation

@IngridPuppet
@IngridPuppet IngridPuppet commented Feb 18, 2026 •
Copy link
Copy Markdown
Contributor

Closes #45231

The implemented JWT format looks like this (updated with review comments):

{
  "header" : {
    "alg" : "HS512",
    "typ" : "JWT",
    "kid" : "a109ad9d-0144-40c9-80e7-42dc7e55b2e6"
  },
  "payload" : {
    "exp" : 1774447450,
    "iat" : 1774447420,
    "iss" : "http://localhost:8080/realms/test",
    "aud" : "http://localhost:8080/realms/test/protocol/openid-connect/token",
    "context" : {
      "credentials_offer_id" : "jPYrg61ZmpG0Dwb7qSn3B5AmiyJuScjtflP001s-jZlacJxhnnx5p8zwAni4GJUQ-pWO_EhZZrzOx1cugo5zjw",
      "target_client_id" : "oid4vci-client",
      "target_user_id" : "0599083e-fb4b-4e9f-8e05-685adfab65a5",
      "nonce" : "OCYXrKWen1TFaCwXvx5RYYwWdEfGbYF1fqlsqnwoO3FCHG5SL-s2fbvTScNLwKtgKvVj8E2tSEUIXDo4Z3dXdQ",
      "authorization_details" : [ {
        "type" : "openid_credential",
        "credential_configuration_id" : "jwt-credential-config-id",
        "credential_identifiers" : [ "jwt-credential" ]
      } ]
    },
    "salt" : "fVLiYLHQ6ALVRF2V2KXyZ5AVh284h2k1TZMBO6k6fF0"
  },
  "signature" : "oLYISMsP4ZlwfDNl8joXQ58kZPVL8yECbAOa3AX_vPCjIpLD9XUKFvJgbUo34CG1h56YMFIOj9qN48_iZit-1A"
}
8000

@VinodAnandan
Copy link
Copy Markdown
Contributor

@IngridPuppet Thank you very much for this PR, it’s greatly appreciated.

I had a quick question regarding the use of "typ": "oid4vci-pre-auth-code+jwt" instead of "typ": "JWT". Could you please share the rationale behind this choice? Additionally, are there any IANA registrations, standards, or other authoritative references that define or recommend this type or format?

If there isn’t a clear standard definition or established best practice supporting it, I would kindly ask that we align this with the existing standards. Thank you very much for your consideration.

@IngridPuppet
Copy link
Copy Markdown
Contributor Author

If there isn’t a clear standard definition or established best practice supporting it, I would kindly ask that we align this with the existing standards. Thank you very much for your consideration.

Hi @VinodAnandan. I understand your point and acknowledge that the typ header introduced is not normative. Let me drop that quick and simply use JWT. Hopefully, it has no impact on the business logic.

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.forms.MultipleTabsLoginTest#testLoginAfterLogoutFromDifferentTab

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...
java.lang.RuntimeException: Error during saving the screenshot!
	at org.arquillian.extension.recorder.screenshooter.browser.impl.BrowserScreenshooter.takeScreenshot(BrowserScreenshooter.java:127)
	at org.arquillian.extension.recorder.screenshooter.browser.impl.TakeScreenshotAndReportService.takeScreenshotAndReport(TakeScreenshotAndReportService.java:60)
	at org.arquillian.extension.recorder.screenshooter.browser.impl.ScreenshotTaker.onTakeScreenshot(ScreenshotTaker.java:79)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#loginActionWithoutExecution

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsParallelLoginTestWithAuthSessionExpiredAndRequiredAction

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#expiredAuthenticationAction_expiredCodeExpiredExecution

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#testWithAuthSessionExpiredInTheMiddle_badRedirectUri

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#testEmptyBaseUrl

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#testRestartFailureWithDifferentClientAfterAuthSessionExpiration

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#expiredAuthenticationAction_currentCodeExpiredExecution

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#testLogoutDifferentBrowserWithAuthenticationSessionStillPresent

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsLoginAndPassiveCheck

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsParallelLoginTestWithAuthSessionExpiredInTheMiddle

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#loginActionWithoutExecutionInRequiredActions

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsParallelLoginTestWithAuthSessionExpiredAndRefreshInTab1

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#testLoginPageRefresh

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#loginWithDifferentClients

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsParallelLoginTestWithAuthSessionExpiredAndRegisterClick

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsParallelLoginTest

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#expiredAuthenticationAction_expiredCodeCurrentExecution

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#testInjectRedirectUriInClientDataAfterAuthSessionExpiration

Keycloak CI - Forms IT (chrome)

org.openqa.selenium.TimeoutException: 
timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=144.0.7559.132)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.14.0-1017-azure', java.version: '25.0.2'
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.oid4vc.issuance.credentialoffer.preauth.JwtPreAuthCodeHandlerTest#shouldGenerateValidPreAuthCode

Keycloak CI - Base IT (6)

org.junit.ComparisonFailure: Must use expected signing algorithm expected:<[E]S256> but was:<[R]S256>
	at org.junit.Assert.assertEquals(Assert.java:117)
	at org.keycloak.testsuite.oid4vc.issuance.credentialoffer.preauth.JwtPreAuthCodeHandlerTest.assertValidPreAuthCodeJwt(JwtPreAuthCodeHandlerTest.java:224)
	at org.keycloak.testsuite.oid4vc.issuance.credentialoffer.preauth.JwtPreAuthCodeHandlerTest.lambda$shouldGenerateValidPreAuthCode$93ae3c06$1(JwtPreAuthCodeHandlerTest.java:53)
	at org.keycloak.testsuite.rest.TestingResourceProvider.runOnServer(TestingResourceProvider.java:773)
...

Report flaky test

@VinodAnandan
Copy link
Copy Markdown
Contributor

@IngridPuppet Could you please update the JWT format in the PR description with the latest changes.

@IngridPuppet
Copy link
Copy Markdown
Contributor Author

@IngridPuppet Could you please update the JWT format in the PR description with the latest changes.

Sure. Done.

@IngridPuppet
IngridPuppet force-pushed the 45231-pre-auth-codes-as-jwts branch 2 times, most recently from b99423c to c04b0b8 Compare February 20, 2026 12:34
@tnorimat tnorimat 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.

Thanks!

@tdiesler
tdiesler commented Feb 23, 2026 •
Copy link
Copy Markdown
Contributor

It's probably not a good idea to serialize the CredentialOfferState directly into the JWT

  • credential_issuer is duplicated in iss
  • expiration is duplicated in exp

What you show above has no authorization_details. Maybe that is included now (by virtue of serializing the entire state), is it? The tx_code is part of that credential order state, it should however not be included in the JWT

@tdiesler
Copy link
Copy Markdown
Contributor

This branch is actually quite a bit behind current main. The CredentialOfferState is now an immutable object that contains authorization_details and tx_code

@IngridPuppet
Copy link
Copy Markdown
Contributor Author

This branch is actually quite a bit behind current main. The CredentialOfferState is now an immutable object that contains authorization_details and tx_code

Hello @tdiesler - Thank you for taking a look. Indeed, the PR needs updating after the recent merge of #46199. I'll do so taking your points into consideration.

What you show above has no authorization_details. Maybe that is included now (by virtue of serializing the entire state), is it? The tx_code is part of that credential order state, it should however not be included in the JWT

Currently, the state is not directly serialized. The model is reused but only public fields are injected into the JWT. Of course, this does not include a potentially sensitive tx_code field; I had that in mind. It also does not seem like authorization_details can be available at that point in the lifecycle of the Pre-Authorized flow. They were not excluded however.

Given these concerns, I acknowledge that introducing a separate model looks more appropriate. I'll update the PR accordingly.

@tdiesler
Copy link
Copy Markdown
Contributor

Perhaps it's worth building your thing on top of #46466 - there we introduce a CredentialOfferProvider as the single entry point for creating CredentialOfferState. You'll find that authorization_details are in fact available from create time & can simply be copied to their relevant targets (i.e. AccessToken Response/JWT and your pre-auth_code JWT).

@IngridPuppet
Copy link
Copy Markdown
Contributor Author

Hello @tdiesler - The PR has been rebuilt on top of the recent changes in main. Please could you take another look when you have a chance?

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

LGTM - very nice :-)

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

@IngridPuppet Thanks for the PR!

I did not yet reviewed, but is it possible to rebase please? There is this change 53e7bdf , which may require some additional updates in your PR (the new feature feature would be needed to be enabled in the migrated test).

@mposolda mposolda self-assigned this Mar 20, 2026
@IngridPuppet
IngridPuppet force-pushed the 45231-pre-auth-codes-as-jwts branch from 6cfebf7 to 3767469 Compare March 23, 2026 10:47
@IngridPuppet
Copy link
Copy Markdown
Contributor Author

Hello @mposolda - PR rebased. Could you take a look when you have a chance?

@IngridPuppet
IngridPuppet requested a review from mposolda March 23, 2026 11:44
@VinodAnandan
Copy link
Copy Markdown
Contributor

@mposolda This PR aims to enhance the security of the pre-authorized code grant. As you may know, this flow does not benefit from protections using PKCE, which can make it more susceptible to risks like phishing, brute force attacks, malware, accidental exposure, replay attacks, and MITM interception. Using a signed JWT instead of a random string helps strengthen the overall security model.

The PR has already been reviewed and approved by @tnorimat and @tdiesler . We are hoping to include it in the 26.6 release, and would greatly appreciate your support in reviewing and progressing it when you have a moment.

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

LGTM

@IngridPuppet
IngridPuppet force-pushed the 45231-pre-auth-codes-as-jwts branch from 3767469 to 00a415b Compare March 24, 2026 09:17
@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.

@IngridPuppet Thanks for this PR and sorry for late review. Added some comments inline. Can you please check?

@mposolda
Copy link
Copy Markdown
Contributor

@IngridPuppet Will be probably good to rebase on top of latest main after recently merged 931d232 (There are no conflicts with your PR, but just to be sure that tests are still OK). Thanks!

@IngridPuppet
IngridPuppet force-pushed the 45231-pre-auth-codes-as-jwts branch 3 times, most recently from 6b33ea1 to f061712 Compare March 25, 2026 15:31
Closes keycloak#45231

Signed-off-by: Ingrid Kamga <Ingrid.Kamga@adorsys.com>
Signed-off-by: Ingrid Kamga <xingridkamga@gmail.com>
@IngridPuppet
IngridPuppet force-pushed the 45231-pre-auth-codes-as-jwts branch from f061712 to 898ab15 Compare March 25, 2026 16:08
Signed-off-by: Ingrid Kamga <Ingrid.Kamga@adorsys.com>
@IngridPuppet
IngridPuppet force-pushed the 45231-pre-auth-codes-as-jwts branch from 898ab15 to c5a894e Compare March 25, 2026 17:33
@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.

@IngridPuppet @tdiesler @tnorimat @VinodAnandan Thanks for the update and reviews!

@mposolda
mposolda merged commit df92e7a into keycloak:main Mar 25, 2026
84 checks passed
@IngridPuppet
IngridPuppet deleted the 45231-pre-auth-codes-as-jwts branch May 12, 2026 10:18
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
…k#46450)

Closes keycloak#45231


Signed-off-by: Ingrid Kamga <Ingrid.Kamga@adorsys.com>
Signed-off-by: Ingrid Kamga <xingridkamga@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OID4VCI] Generate pre-authorized codes using the JWT format

5 participants

0