Skip to content

[identity] Add support for session id in mobile flows#1103

Merged
cleftheris merged 16 commits into
developfrom
feature/identity-support-mobile-sessionId
Jul 21, 2026
Merged

[identity] Add support for session id in mobile flows#1103
cleftheris merged 16 commits into
developfrom
feature/identity-support-mobile-sessionId

Conversation

@NikosDevPhp

@NikosDevPhp NikosDevPhp commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@cleftheris
Squash if merged.

  1. The sid claim is stripped by default because JwtClaimTypes.SessionId is on IdentityServer4's hardcoded protocol-claim filter lists in Constants.Filters — both ProtocolClaimsFilter and ClaimsServiceFilterClaimTypes, the latter being described as the filter for claims returned from the profile service prior to creating tokens - not applicable here it strips before.

This happens after GetProfileData. ExtendedTokenResponseGenerator adds the claim in ValidatedRequest.Subject -> ITokenService -> DefaultClaimsService.GetAccessTokenClaimsAsync / GetIdentityTokenClaimsAsync -> ExtendedProfileService

Checked against latest IS4 I have, for a previous - should be close to latest. - see below.
https://github.com/DuendeArchive/IdentityServer4/blob/295026919db5bec1b0c8f36fc89e8aeb4b5a0e3f/src/IdentityServer4/Services/DefaultClaimsService.cs

  1. Instead of overriding something in the chain, we can use the intented way which should be
    include sid (if present) in access tokens #3955 DuendeArchive/IdentityServer4#4202

  2. There is a discrepancy between IS4 and Duende when UpdateAccessTokenClaimsOnRefresh is set to true on a client.
    Refresh_Token_Preserves_SessionId_When_Client_Updates_Claims_On_Refresh intentionally skipped.

Probably here is the root cause:
IS4 does not populate the SessionId:
https://github.com/DuendeArchive/IdentityServer4/blob/5e40bd18fbf030d0158a15532eb8381c454b53da/src/IdentityServer4/src/Validation/Default/TokenRequestValidator.cs#L526

Duende populates the SessionId: https://github.com/DuendeSoftware/products/blob/e3479e955b0c5515d76391561f76d18b2074a2ea/identity-server/src/IdentityServer/Validation/Default/TokenRequestValidator.cs#L772

This PR fix made only on Duende(?)
DuendeArchive/Support#99
DuendeSoftware/products#944

@NikosDevPhp
NikosDevPhp requested a review from cleftheris July 13, 2026 10:12
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Fixed
@NikosDevPhp
NikosDevPhp force-pushed the feature/identity-support-mobile-sessionId branch from c0fedc0 to 4f86945 Compare July 20, 2026 14:57
…ithub.com/indice-co/Indice.AspNet into feature/identity-support-mobile-sessionId

# Conflicts:
#	test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs
@NikosDevPhp
NikosDevPhp marked this pull request as ready for review July 20, 2026 15:31
Copilot AI review requested due to automatic review settings July 20, 2026 15:31

Copilot AI 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.

Pull request overview

This PR introduces explicit sid (session id) population for mobile-oriented token flows, aligning behavior across password/extension grants and adding integration coverage to ensure session id issuance/preservation (including refresh scenarios and server-side sessions interaction).

Changes:

  • Populate ValidatedRequest.SessionId during password and extension grant token processing so sid is present in issued tokens.
  • Add/extend integration tests validating sid issuance, refresh preservation, and expected server-side session behavior for mobile clients.
  • Bump Identity/IdentityUI version prefixes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
test/Indice.Features.Identity.Tests/MobileSessionIdServerSideSessionsTests.cs Adds a dedicated NET9+ integration test suite around mobile session id + server-side sessions behavior.
test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Extends existing integration tests to assert sid exists across multiple token issuance flows and refresh.
src/Indice.Features.Identity.Core/ResponseHandling/ExtendedTokenResponseGenerator.cs Sets ValidatedRequest.SessionId for password and extension grants to ensure sid is emitted.
src/Directory.Build.props Increments Identity/IdentityUI version prefixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Outdated
Comment thread test/Indice.Features.Identity.Tests/MobileSessionIdServerSideSessionsTests.cs Outdated
Comment thread test/Indice.Features.Identity.Tests/CustomGrantsIntegrationTests.cs Outdated
NikosDevPhp and others added 4 commits July 20, 2026 18:40
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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

🚀

@cleftheris
cleftheris merged commit 52f37e0 into develop Jul 21, 2026
7 checks passed
@cleftheris
cleftheris deleted the feature/identity-support-mobile-sessionId branch July 21, 2026 09:53
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.

4 participants