Skip to content

feat(client): implement secure token management and session restoration - #174

Closed
mckaragoz wants to merge 1 commit into
devfrom
feature/client-token-management
Closed

mckaragoz wants to merge 1 commit into
devfrom
feature/client-token-management

Conversation

@mckaragoz

Copy link
Copy Markdown
Contributor

Summary

  • Add opt-in PureJwt token management for Blazor WebAssembly with startup restoration, explicit refresh, authenticated Resource API requests, and logout.
  • Document a Blazor WASM, UAuthHub, and Resource API setup, including grant delivery, cookies, CORS, antiforgery, and a replaceable token store.

Client architecture and security

  • Store the access JWT and expiration in a replaceable, scoped C# memory store. Authentication events use the same client scope.
  • Let PKCE navigation set the Hub refresh cookie. On return or F5, the existing session coordinator refreshes once and the Hub validates the new JWT before the existing authentication state receives the snapshot.
  • Coalesce in-flight refresh calls within a client scope. Canceling a caller's wait lets an in-flight rotation finish and reconcile the cookie and access token.
  • Attach bearer credentials only to the configured HTTPS Resource API origin. Reject redirects, omit browser cookies for bearer resource requests, and retain device and application profile headers.

Server changes

  • Reuse the existing grant delivery, refresh rotation, replay protection, and antiforgery paths. Expose the access header and its expiration to allowed Hub origins for header access and cookie refresh delivery.
  • Keep PureJwt chain revocation tied to authenticated logout. Expire the refresh cookie using its configured attributes and clear the client's access credential and UI state after confirmed logout.

Modes and known limitations

  • Enable the new flow with UsePureJwtBrowserTokens on Blazor WASM against a PureJwt Hub and Resource API. The client expects a Bearer-formatted uat header and an HttpOnly, Secure refresh cookie.
  • PureOpaque continues to use its cookie/session flow. Hybrid and SemiHybrid retain their existing mode behavior and support limits. Browser bearer transport is WASM-specific, and the store registration is scoped for server-side consumers.
  • Cross-site refresh and logout depend on browser cookie policies. WASM memory remains accessible to same-origin script execution. Issued JWTs continue to follow their normal validity and expiration rules after logout.

Verification

  • Client Blazor and Server builds passed on .NET 8, 9, and 10.
  • The .NET 10 unit suite passed 3,519 tests.
  • The .NET 10 integration suite passed 488 tests.
  • The Node browser transport suite passed 29 tests.
  • Headless Chromium with three HTTPS origins verified PKCE login, bearer Resource API access, F5 cookie rotation, explicit refresh, authenticated logout, and anonymous startup after logout.

Deferred to PR #2

Proactive refresh and expiration timers, request- or 401-triggered refresh and retry, advanced network recovery, multi-tab coordination and synchronization, optional access-token possession requirements, and sender-constrained or proof-of-possession tokens.

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.81609% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.07%. Comparing base (7b4190a) to head (2b3a9b9).

Files with missing lines Patch % Lines
...am.UltimateAuth.Client/Services/UAuthFlowClient.cs 64.78% 19 Missing and 6 partials ⚠️
...ateAuth.Client.Blazor/Components/UAuthApp.razor.cs 20.00% 7 Missing and 1 partial ⚠️
...Client.Blazor/Infrastructure/SessionCoordinator.cs 46.66% 5 Missing and 3 partials ⚠️
...mateAuth.Server/Endpoints/LogoutEndpointHandler.cs 80.76% 2 Missing and 3 partials ⚠️
...UltimateAuth.Client/AuthState/UAuthStateManager.cs 73.33% 2 Missing and 2 partials ⚠️
.../Options/Validators/UAuthClientOptionsValidator.cs 0.00% 1 Missing and 1 partial ⚠️
...Client.Blazor/Infrastructure/UAuthRequestClient.cs 85.71% 0 Missing and 1 partial ⚠️
...lazor/Infrastructure/UAuthResourceRequestClient.cs 85.71% 0 Missing and 1 partial ⚠️
...ateAuth.Client/Abstractions/ISessionCoordinator.cs 0.00% 1 Missing ⚠️
...teAuth.Client/Services/Abstractions/IFlowClient.cs 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (67.81%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #174      +/-   ##
==========================================
- Coverage   88.20%   88.07%   -0.13%     
==========================================
  Files         610      614       +4     
  Lines       20416    20568     +152     
  Branches     2456     2489      +33     
==========================================
+ Hits        18007    18115     +108     
- Misses       1545     1576      +31     
- Partials      864      877      +13     
Flag Coverage Δ
framework 88.07% <67.81%> (-0.13%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mckaragoz mckaragoz closed this Nov 24, 2026
@mckaragoz
mckaragoz deleted the feature/client-token-management branch November 25, 2026 18:41
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.

1 participant