8000 [OID4VCI] Add support for `authorization_code` grant - Part4 by tdiesler · Pull Request #46950 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

[OID4VCI] Add support for authorization_code grant - Part4 - #46950

Merged
mposolda merged 6 commits into
keycloak:mainfrom
tdiesler:ghi46261-p4
Mar 12, 2026
Merged

mposolda merged 6 commits into
keycloak:mainfrom
tdiesler:ghi46261-p4

Conversation

@tdiesler
@tdiesler tdiesler commented Mar 6, 2026 •
Copy link
Copy Markdown
Contributor

closes #47100

related #46385

[OID4VCI] Add support for authorization_code grant - Part4

@wistefan wistefan 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, only some minor remarks

@Captain-P-Goldfish Captain-P-Goldfish 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.

not finished yet, I will continue tomorrow with the review

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

@tdiesler Thanks for the PR!

During the review, I spot few things. Especially during the pre-authorized code grant, the credential-request does not check at all that offerState exists as it is always null. This is due the fact that client session note CREDENTIAL_OFFER_ID_NOTE is null in the credential request (as this client session is different than the one used in pre-authorized grant request and moreover pre-authorized grant uses transient user session). It seems we have some gaps in the test coverage since this was not caught by the automated tests.

Storing of the offerId inside client session is not ideal even for authorization-code grant as there is single AuthenticatedClientSession per browser session, however there might be more access tokens for various different VC with multiple different offers inside same browser session.

It should rather work better if the offer ID is stored directly inside access token instead of client session. This fixes the issues above and makes sure that correct access-token, which was returned from the token-response related to credential-offer will also consume the same credential-offer inside credential request.

This "contract" between access-token and credential-offer was available before this PR as credential_identifier from access token was used as a link to obtain credential offer. However this contract was now lost with latest changes as credential_identifier is not used for this purpose anymore. So we need something else inside access token to make sure this correlation between access-token and credential-offer still exists.

I've sent PR tdiesler#2 to your branch, which adds offer ID as claim into the access token instead of using client session note. It is stored within authorization_details, which should be OK as OID4VC specification mentions in the section 5.1 Additional authorization_details data fields MAY be defined and used when the type value is openid_credential. Note that this effectively defines an authorization details type that is never considered invalid due to unknown fields.. Merging that PR should automatically update this PR.

I've also added some test scenarios, which should work (and AFAIK they pretty much worked before your PR, but stopped working).

@tdiesler
Copy link
Copy Markdown
Contributor Author

@tdiesler Thanks for the PR!

During the review, I spot few things. Especially during the pre-authorized code grant, the credential-request does not check at all that offerState exists as it is always null. This is due the fact that client session note CREDENTIAL_OFFER_ID_NOTE is null in the credential request (as this client session is different than the one used in pre-authorized grant request and moreover pre-authorized grant uses transient user session). It seems we have some gaps in the test coverage since this was not caught by the automated tests.

Storing of the offerId inside client session is not ideal even for authorization-code grant as there is single AuthenticatedClientSession per browser session, however there might be more access tokens for various different VC with multiple different offers inside same browser session.

It should rather work better if the offer ID is stored directly inside access token instead of client session. This fixes the issues above and makes sure that correct access-token, which was returned from the token-response related to credential-offer will also consume the same credential-offer inside credential request.

This "contract" between access-token and credential-offer was available before this PR as credential_identifier from access token was used as a link to obtain credential offer. However this contract was now lost with latest changes as credential_identifier is not used for this purpose anymore. So we need something else inside access token to make sure this correlation between access-token and credential-offer still exists.

I've sent PR tdiesler#2 to your branch, which adds offer ID as claim into the access token instead of using client session note. It is stored within authorization_details, which should be OK as OID4VC specification mentions in the section 5.1 Additional authorization_details data fields MAY be defined and used when the type value is openid_credential. Note that this effectively defines an authorization details type that is never considered invalid due to unknown fields.. Merging that PR should automatically update this PR.

I've also added some test scenarios, which should work (and AFAIK they pretty much worked before your PR, but stopped working).

UR a hero :-)

Yes, some time ago I also discovered the credential offer id as always null in the credential request, traced it back to the transient user session and came to the conclusion that this id should be stored in the access token directly (as a proprietary claim) - exactly as you say and I'm very grateful for you making the effort of fixing it. I wanted to raise this issue as a follow-up as soon as everyone can see it.

I'll have a look and get back to you when I've managed to digest your proposed changes - thanks.

@tdiesler
tdiesler force-pushed the ghi46261-p4 branch 2 times, most recently from 25064e2 to 58c5517 Compare March 12, 2026 09:14
tdiesler and others added 3 commits March 12, 2026 11:39
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
…ated tests.

Signed-off-by: mposolda <mposolda@gmail.com>
@tdiesler
Copy link
Copy Markdown
Contributor Author

@mposolda The generated authorization_details for the offer state did not contain the credential_offer_id. It slipped through because equality & hashCode ignored it too. I fixed that and renamed OFFER_ID => CREDENTIAL_OFFER_ID as will be done in part5 anyway. Otherwise, great - thanks.

@tdiesler
tdiesler force-pushed the ghi46261-p4 branch 2 times, most recently from 1d14706 to b800e32 Compare March 12, 2026 11:30
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
…lity/hashCode

Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
@Captain-P-Goldfish Captain-P-Goldfish 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

@mposolda
Copy link
Copy Markdown
Contributor

@mposolda The generated authorization_details for the offer state did not contain the credential_offer_id. It slipped through because equality & hashCode ignored it too. I fixed that and renamed OFFER_ID => CREDENTIAL_OFFER_ID as will be done in part5 anyway. Otherwise, great - thanks.

@tdiesler Yes, I did not originally added the offer_id to the authzDetails entry in the cache as offerState itself is saved in the cache by the corresponding credential_offer_id to be the key, so strictly speaking it is not needed in the cache itself. But no problem to have it in the cache.

The tests I've added could be probably simplified (The code for doing the login and whole accessToken obtain could be likely extracted to some private method as it is same code used by multiple tests). But that can be done as a follow-up though :-)

PR looks good to me as well. Thanks for the latest updates!

@mposolda
mposolda merged commit 6efb394 into keycloak:main Mar 12, 2026
84 checks passed
@tdiesler
Copy link
Copy Markdown
Contributor Author

Hallelujah :-D

@tdiesler
tdiesler deleted the ghi46261-p4 branch March 12, 2026 15:14
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
…k#46950)

closes keycloak#47100


Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Signed-off-by: mposolda <mposolda@gmail.com>
Co-authored-by: mposolda <mposolda@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.

Initial support for issuer_state in the credential offer. Align credential_identifiers in authorization details

4 participants

0