Architecture Decision Record
ADR-051: Client-Side Authentication Token Lifecycle Across Render Modes
Status
Accepted (2026-07-23). Revised 2026-08-07 (the SecureStorage-backed MAUI storage is hoisted from
the apps into the framework's MAUI-TFM package). Revised 2026-08-14 (SetTokensAsync writes the
refresh token and the access token under one shared guard, so a failed refresh-token write also drops
both tokens). Revised 2026-08-31 (MAUI storage splits into a freshness layer over a raw
ISecureTokenStore, and all three storage services carry the 30-second expiry check plus
single-flight refresh). Revised 2026-10-01 (citations re-anchored; the SkipBearer exemption and the
browser SetTokensAsync throw on a failed cookie write recorded). Revised 2026-10-06: the browser
refresher reports a three-way TokenAcquisition, the browser storage services hold a 15-second
anonymous grace, the MAUI single-flight is process-wide, and the bearer handler leaves an existing
Authorization header alone. Revised 2026-10-07: on the same-origin API proxy hosts (both
consumers) the Blazor Server circuit refreshes and seeds cookies through a protected handoff, the
browser receives only a claims-only token, and the proxy strips and re-stamps the bearer; the MAUI
refresher treats a 409 as transient and keeps the stored pair. See the Revisions below. Revised
2026-10-21: the MAUI refresher reports no session only for a refused token (400, 401 or 403), no
stored pair or an empty access token (other failures are unavailable), the Server storage is
recorded as seeing a non-null HttpContext on the circuit and telling it from the prerender by a
hub-connection request and by memory authority, both browser storage services discard a hydrate
overtaken by a login or logout, and the bearer handler marks replay safety on a transport failure;
anchors refreshed. Revised 2026-10-26: both browser storage services raise SessionEnded
(ISessionAwareTokenStorage) when a held session ends on the server and the auth-state provider
signs the shell out on it (no MAUI equivalent), the WASM clients pre-hydrate the token through
TokenHydrationWarmup, and Decision anchors are refreshed. Revised 2026-10-28: anchors refreshed
after the 2026-10-27 ADC and Store Server host Program.cs changes. Revised 2026-11-23: the
MAUI freshness layer is SecureStoreTokenStorageService in MMCA.Common.UI (only the raw store stays
in the MAUI package), all three storage services are session-aware so the MAUI head also signs out on
a definitive "no session", an API 401 to a request that carried a bearer now drives one refresh
through RenewRejectedAccessTokenAsync, the auth-state provider forgets list-page state rather than
a UI read cache, and the Server host wiring is recorded in the shared AddMmcaBlazorWebHost.
Revised 2026-12-03 (MMCA.Common v1.331.0): the server is the only writer of the browser session
cookies, the browser sync only clears them, and /auth/session/token always answers a claims-only
token; see the Revision (2026-12-03) at the end.
Context
ADR-022 and ADR-050 describe the two server halves of authentication: the Blazor host's HttpOnly session cookie that survives SSR prerender (ADR-022), and the Identity service's single rotating refresh token with reuse detection (ADR-050). Neither covers the client half: how a Blazor or MAUI head actually holds an access token, attaches it to API calls, and reacquires one when it nears expiry.
The awkward part is that the same UI code runs under three different render heads with three different safe-storage stories:
- Blazor Server (interactive circuit): no direct DOM access from the server, JS interop is
available only once the circuit is live, and during SSR prerender there is no circuit at all,
only an
HttpContext. - Blazor WebAssembly: runs in the browser with a DOM and an XSS surface, so persisting a refresh token where JS can read it (localStorage) is unsafe.
- MAUI (Blazor Hybrid WebView): a native process with OS-backed secure storage and no cross-origin browser cookie jar to lean on.
A single access token acquisition path cannot serve all three: the browser heads must keep the refresh token out of JS reach, while MAUI has no same-origin UI host to proxy a refresh through and must talk to the API cross-origin. We wanted the application-facing surface (how a page reads auth state, how an outgoing API request gets its bearer token) to be identical across heads, with the head-specific storage and refresh mechanics hidden behind narrow abstractions.
Decision
Model the client token lifecycle as three small abstractions (ITokenStorageService, the
freshness-checked persistence every caller consumes; ISecureTokenStore, raw persistence for the one
head that persists tokens itself; ITokenRefresher for reacquisition) plus a shared bearer-attaching
handler and a shared JWT-driven auth-state provider. Each head registers the implementations that
match its safe-storage story; the UI code above them never branches on render mode.
ITokenRefresherabstracts reacquisition, one implementation per head family. The interface exposes a singleAcquireAccessTokenAsyncthat returns a fresh access token ornullwhen no valid session exists (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ITokenRefresher.cs:17,ITokenRefresher.cs:24). Where the refresh token lives and how rotation happens are internal to the implementation.- Browser heads refresh through the same-origin proxy.
SameOriginProxyTokenRefresher(the WASM client's refresher, and the Blazor Server default until the same-origin API proxy replaces it on the circuit, below) invokesmmcaAuthSession.getTokenover JS interop (SameOriginProxyTokenRefresher.cs:16,SameOriginProxyTokenRefresher.cs:27), which issues aPOST /auth/session/tokenwithcredentials:'same-origin'so the browser sends its HttpOnly auth cookies and the UI host validates-or-refreshes server-side, returning a browser token (the access token by default; a claims-only copy on a same-origin API proxy host, below) (MMCA.Common/Source/Presentation/MMCA.Common.UI/wwwroot/mmca-auth-cookie.js:47-63). The refresh token never reaches JS. The script answersnullonly for the endpoint's 401 and throws on any other non-OK status (mmca-auth-cookie.js:54-59). The refresher also implementsISessionAwareTokenRefresher, whoseTryAcquireAccessTokenAsyncreturns a three-wayTokenAcquisition: acquired, no session (a blank token), or unavailable when interop is missing (SSR prerender, disconnected circuit), the call is cancelled, or the endpoint fails transiently (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ISessionAwareTokenRefresher.cs:12,TokenAcquisition.cs:9,SameOriginProxyTokenRefresher.cs:23-37). The plainAcquireAccessTokenAsynccollapses that to the token ornull, so it never throws (SameOriginProxyTokenRefresher.cs:19-20). - On a same-origin API proxy host the browser never holds a credential. Both consumer Server
hosts build through the shared
AddMmcaBlazorWebHostandUseMmcaBlazorWebPipeline(MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:26,Program.cs:128on net11.0 andProgram.cs:130on the net10.0 line;MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:30,Program.cs:92), which callAddCommonSameOriginApiProxyandMapCommonSameOriginApiProxy(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hosting/BlazorWebHostExtensions.cs:142,BlazorWebHostExtensions.cs:210; ADR-131). That call replaces the Server circuit'sITokenRefresherwithHandoffTokenRefresherand itsISessionCookieSyncwithHandoffSessionCookieSync(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyServiceExtensions.cs:79-80). They callmmcaAuthHandoff.getToken/mmcaAuthHandoff.setCookie(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/HandoffSessionServices.cs:25,HandoffSessionServices.cs:59,mmca-auth-cookie.js:53-87) against/auth/session/handoffand/auth/session-cookie/handoff(SessionHandoffEndpoints.cs:19-20), so the page carries onlySessionHandoffProtectorciphertext and the circuit opens it server-side; a handoff it cannot open is unavailable, not "no session" (HandoffSessionServices.cs:31-35). Boot fails if a later registration displaces either replacement (SameOriginApiProxyEndpointExtensions.cs:64-92). The WASM client's/auth/session/tokenalways answers with an unsignedalg:noneclaims copy rather than the access token (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:105-107,SessionClaimsToken.cs:14,SessionClaimsToken.cs:17,SessionClaimsToken.cs:25-34). - MAUI refreshes directly against the API.
DirectApiTokenRefresherreads the stored access and refresh tokens out of OS SecureStorage throughISecureTokenStore, posts them to the API's cross-originauth/refreshendpoint, and persists the rotated pair back (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/DirectApiTokenRefresher.cs:40-42,DirectApiTokenRefresher.cs:53-54,DirectApiTokenRefresher.cs:61-66,DirectApiTokenRefresher.cs:103). It is anISessionAwareTokenRefreshertoo: a409 Conflict(Auth.RefreshSuperseded) is transient and never clears the stored pair, answering with a newer pair another refresh in this process already stored or otherwise unavailable, so a stolen-and-rotated token is caught by the server's reuse detection (BR-206) on the next presentation (DirectApiTokenRefresher.cs:25-32,DirectApiTokenRefresher.cs:85-88,DirectApiTokenRefresher.cs:111-121). Only a refusal of the presented token (400, 401 or 403) is no session; every other non-success status (a 408, a 429, a 5xx) is unavailable (DirectApiTokenRefresher.cs:90-95, rationale atDirectApiTokenRefresher.cs:33-38), and so are a dropped connection and anHttpClienttimeout the caller did not request (DirectApiTokenRefresher.cs:73-81). No session is also the answer when no pair is stored (DirectApiTokenRefresher.cs:56-59) and when a success body carries an empty access token (DirectApiTokenRefresher.cs:98-101). The MAUI storage hydrates through the session-awareTryAcquireAccessTokenAsync: an unavailable result reaches its callers as anullbearer and leaves the stored pair alone, while a definitive "no session" for a held pair clears it and raisesSessionEnded; only a refresher that is not session-aware takes the collapsingAcquireAccessTokenAsync(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/SecureStoreTokenStorageService.cs:251-256,SecureStoreTokenStorageService.cs:261-264,SecureStoreTokenStorageService.cs:274-276). It takes the raw store rather thanITokenStorageServiceon purpose: every operation it performs is a raw read or write, and depending on the freshness-checking storage instead would close the loop and let a refresh re-enter the acquisition that started it (DirectApiTokenRefresher.cs:12-17). This head has no browser DOM (and thus no XSS surface), so direct token handling is acceptable. ITokenStorageServiceabstracts persistence, one implementation per head. The interface holds access-token and refresh-token get/set/clear (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ITokenStorageService.cs:8). The two browser implementations keep the access token in memory only and never hand a refresh token to JS:WasmTokenStorageService(in MMCA.Common.UI) hydrates the in-memory token on demand from the cookie and returnsnullfor the refresh token unconditionally (WasmTokenStorageService.cs:26,WasmTokenStorageService.cs:71-110,WasmTokenStorageService.cs:140);ServerTokenStorageService(in MMCA.Common.UI.Web) answers from the HttpOnly cookie during SSR prerender and holds an in-memory token on the interactive circuit (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Services/ServerTokenStorageService.cs:48,ServerTokenStorageService.cs:107-152,ServerTokenStorageService.cs:265-318). The circuit still has anHttpContext: the request that opened the hub connection, whose cookie is stale by construction (ServerTokenStorageService.cs:29-41). So the cookie answers a hub-connection request only until this instance has stored, cleared or hydrated a token, and then only while that cookie is fresh or absent; an expired one goes to the refresher instead (ServerTokenStorageService.cs:78,ServerTokenStorageService.cs:325-353,ServerTokenStorageService.cs:360-362). A connection request whose cookie carries a token also marks the circuit as holding a session (ServerTokenStorageService.cs:347-350). Its refresh-token read returns the cookie value whenever anHttpContextis present, which on the circuit is that connection request's cookie (ServerTokenStorageService.cs:194-201). Both browser services discard a hydrate whose acquisition was in flight when a login or logout landed, through a token-version counter thatSetTokensAsyncbumps andClearTokensAsyncbumps both before and after its cookie clear (WasmTokenStorageService.cs:48,WasmTokenStorageService.cs:145,WasmTokenStorageService.cs:161,WasmTokenStorageService.cs:172,WasmTokenStorageService.cs:222-225,ServerTokenStorageService.cs:72,ServerTokenStorageService.cs:206,ServerTokenStorageService.cs:224,ServerTokenStorageService.cs:238,ServerTokenStorageService.cs:291-294). Both browser services remember a definitive "no session" for a 15-second anonymous grace, so an anonymous visitor is answered from memory instead of one token POST per API call; anullfrom the refresher starts it unless anISessionAwareTokenRefresherreports the result unavailable (a plainITokenRefresher'snullcounts as no session), andSetTokensAsyncends it at once (WasmTokenStorageService.cs:34,WasmTokenStorageService.cs:78-81,WasmTokenStorageService.cs:146,WasmTokenStorageService.cs:229-232,ServerTokenStorageService.cs:58,ServerTokenStorageService.cs:120-123,ServerTokenStorageService.cs:207, hydrate atServerTokenStorageService.cs:265-318). All three shipped refreshers are session-aware, and all three storage services implementISessionAwareTokenStorage, whoseSessionEndedevent fires once when a session-aware refresher answers a definitive "no session" for a session the storage held (a session revoked from another device, or a deleted account); a transient failure never raises it (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ISessionAwareTokenStorage.cs:12,ISessionAwareTokenStorage.cs:18,WasmTokenStorageService.cs:29,WasmTokenStorageService.cs:58,WasmTokenStorageService.cs:238-244,ServerTokenStorageService.cs:53,ServerTokenStorageService.cs:88,ServerTokenStorageService.cs:309-315). On MAUI the event is process-wide, like the single-flight below, and the definitive answer also clears the stored pair (SecureStoreTokenStorageService.cs:59,SecureStoreTokenStorageService.cs:76,SecureStoreTokenStorageService.cs:81-110,SecureStoreTokenStorageService.cs:274-276). The interface also declaresRenewRejectedAccessTokenAsync(a no-op by default), which the bearer handler calls for an API 401 (below): when the storage still holds the rejected token it runs ONE refresh through the same single-flight, so a definitive "no session" ends the session exactly as an expired token's refresh does, and a token the storage no longer holds changes nothing (ISessionAwareTokenStorage.cs:20-37,WasmTokenStorageService.cs:118-137,ServerTokenStorageService.cs:163-192,SecureStoreTokenStorageService.cs:156-175). The one exception is the Server storage during the SSR prerender, which still answers from the cookie token and has no JS interop to refresh with, so it returns that token unchanged and the circuit that follows re-checks the session (ServerTokenStorageService.cs:160-161,ServerTokenStorageService.cs:178-181). A session therefore ends from a refused refresh or from an API 401, not only when the token expires. Each WASM client also startsTokenHydrationWarmup.WarmAsyncafterbuilder.Build()and discards the task, so the first hydration overlaps first render instead of running inline on the first API call; it only reads throughITokenStorageServiceand swallows every failure (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/TokenHydrationWarmup.cs:26,TokenHydrationWarmup.cs:37-58,MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web.Client/Program.cs:95,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web.Client/Program.cs:87). The MAUI implementation is framework-shared too and is a pair:SecureStoreTokenStorageService(in MMCA.Common.UI, beside the browser services) is the freshness-checking layer (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/SecureStoreTokenStorageService.cs:55-59) over the rawISecureTokenStore, implemented in the MAUI package byMauiSecureTokenStore, which backs ontoSecureStorage.Default(platform secure enclaves) and guards every read and write so an OS-invalidated keystore entry degrades to one clean re-login instead of an unhandled throw on launch (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiSecureTokenStore.cs:22,MauiSecureTokenStore.cs:69-85,MauiSecureTokenStore.cs:91-104,MauiSecureTokenStore.cs:107-120); both MAUI heads register the pair through the oneAddCommonMauiTokenStoragecall (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:115,DependencyInjection.cs:117-118).ISecureTokenStoreisolates raw persistence, and only MAUI implements it. It reads back exactly what was written and never triggers a refresh (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ISecureTokenStore.cs:16). Splitting it out ofITokenStorageServiceis what keeps the MAUI graph acyclic: storage depends on the refresher, and the refresher depends on the raw store rather than back on storage (ISecureTokenStore.cs:4-9). The browser heads implement nothing here, because they hold the access token in memory and leave the refresh token in an HttpOnly cookie, so they have no raw store to expose (ISecureTokenStore.cs:10-14).- The server writes the browser HttpOnly cookies; the browser only clears them.
SetTokensAsyncon both browser storage services caches the access token in memory and callsISessionCookieSync.SyncAsync(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/WasmTokenStorageService.cs:130,:141;MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Services/ServerTokenStorageService.cs:184,:197; contractMMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/ISessionCookieSync.cs:8,:15,:20). The browser implementation,JsFetchSessionCookieSync, writes nothing there and reports success, because the server is the only writer of those cookies and already wrote them when it obtained the pair; the refresh token never transits JS (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/JsFetchSessionCookieSync.cs:15,:24, class remarks:5-10). ItsClearAsyncfiresmmcaAuthCookie.clear, a same-originDELETE /auth/session-cookietried twice, so the resultingSet-Cookielands in the user's cookie jar (JsFetchSessionCookieSync.cs:27,mmca-auth-cookie.js:7-23). The sync is registered viaAddClientAuthSessionCookieSync(MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:303-307), which the shared Server host and both WASM clients call (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hosting/BlazorWebHostExtensions.cs:124;MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web.Client/Program.cs:49,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web.Client/Program.cs:52). The cookies are written on two server paths: the Server circuit seeds them through the protected handoff (above), and the proxy'sTokenIssuingrewrite writes them from a sign-in response and hands the browser the claims-only token withrefreshTokenemptied (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginProxyTransformer.cs:114-117,SameOriginProxyTransformer.cs:135,SameOriginProxyTransformer.cs:258-260). - Every outgoing API request is bearer-stamped by one handler.
AuthDelegatingHandlerreads the current access token fromITokenStorageServiceand attaches it as aBearerauthorization header (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthDelegatingHandler.cs:36,AuthDelegatingHandler.cs:194,AuthDelegatingHandler.cs:197). It is registered into the shared named"APIClient"HttpClient pipeline viaAddHttpMessageHandler(DependencyInjection.cs:140,DependencyInjection.cs:150,DependencyInjection.cs:172), so the handler is head-agnostic: it depends only on the storage abstraction, which supplies the correctly-hydrated token per head. Two requests pass through without reading storage: one that sets theSkipBeareroption (AuthDelegatingHandler.cs:44,AuthDelegatingHandler.cs:187-190), which the MAUI refresh POST sets (DirectApiTokenRefresher.cs:66), and one that already carries anAuthorizationheader, so a forced-refresh replay keeps the token it just acquired instead of resending the rejected one (AuthDelegatingHandler.cs:12-18,AuthDelegatingHandler.cs:192). The handler also catches anHttpRequestException, marks on it whether the request may be resent, and rethrows, so the shared retry policy can tell a replay-safe request from one that may not be resent (AuthDelegatingHandler.cs:131-141). It reads the response too: a 401 to a request that carried a bearer is reported throughRenewRejectedAccessTokenAsyncto the storage that attached that token (tracked per token, because the handler's own scope is not the component's), for one refresh; the 401 itself is passed back unchanged and never replayed, and a 401 to a token that renewal produced is not reported again, so an API that keeps refusing a fresh token cannot drive a refresh per request (AuthDelegatingHandler.cs:20-34,AuthDelegatingHandler.cs:205-208,AuthDelegatingHandler.cs:310-341). A 403 whose Problem Details body carries the multi-factor-required code raisesMultiFactorRequiredSignalfor that storage instead (AuthDelegatingHandler.cs:209-212,AuthDelegatingHandler.cs:231-252). On a WASM client of a proxy host the handler's bearer never reaches the API: the"APIClient"base address is the proxy endpoint and an innermostSameOriginProxyRequestHandlerstrips everyAuthorizationheader (DependencyInjection.cs:146-147,DependencyInjection.cs:162,DependencyInjection.cs:175-181), and the host proxy stamps the cookie session's bearer server-side: the endpoint takes the bearer from the validated-or-refreshed cookie session and the transformer sets it as theAuthorizationheader (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyEndpoint.cs:99-113,SameOriginProxyTransformer.cs:77). - Blazor auth state is derived from the JWT client-side.
JwtAuthenticationStateProviderreads the stored access token, parses and expiry-checks it without server validation, and builds an authenticatedClaimsPrincipalfrom the token's claims, falling back to anonymous on any failure (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/JwtAuthenticationStateProvider.cs:24,JwtAuthenticationStateProvider.cs:61-94,JwtAuthenticationStateProvider.cs:78,JwtAuthenticationStateProvider.cs:89-93). Client-side parsing keeps the UI responsive (AuthorizeViewreacts immediately after login or logout viaNotifyUserAuthentication/NotifyUserLogout,JwtAuthenticationStateProvider.cs:100,JwtAuthenticationStateProvider.cs:112); the WebAPI still performs full token validation on every request. The provider subscribes toSessionEndedwhen its storage is anISessionAwareTokenStorage(it does not implement the interface), and on that event forgets the per-tab list-page state held by the optionalListPageStateServiceits one constructor takes and flips the state to anonymous throughNotifyUserLogout, so a session ended on the server signs the shell out instead of leaving it signed in behind 401s (JwtAuthenticationStateProvider.cs:41-54,JwtAuthenticationStateProvider.cs:50-53,JwtAuthenticationStateProvider.cs:145-151). Since all three storage services are session-aware, this holds on every head. - Concurrent callers share one refresh. All three storage services proactively reacquire when the
token they hold is within a 30-second expiry skew and collapse concurrent acquisitions (delegating
handler, auth-state provider, SignalR) onto a single in-flight hydration
(
WasmTokenStorageService.cs:31,WasmTokenStorageService.cs:87-92,ServerTokenStorageService.cs:55,ServerTokenStorageService.cs:129-134,SecureStoreTokenStorageService.cs:61,SecureStoreTokenStorageService.cs:63,SecureStoreTokenStorageService.cs:67,SecureStoreTokenStorageService.cs:215-236). The browser services hold that slot per instance; on MAUI it is process-wide (static), as are the token version and theSessionEndedevent, because theAuthDelegatingHandlerthatIHttpClientFactorybuilds resolves its own scoped storage instance in its handler scope, and a per-instance slot let that scope and the component scope each rotate the same refresh token, which the server reads as reuse and answers by revoking the session (SecureStoreTokenStorageService.cs:31-39,SecureStoreTokenStorageService.cs:74). On MAUI the check reads through the raw store first, so a token recovered from the enclave hours later is refreshed rather than handed to a caller as a bearer that answers 401 (SecureStoreTokenStorageService.cs:115-116). After a stale-token refresh inGetAccessTokenAsyncthat produced a token, and only once the single-flight slot is cleared, the MAUI storage reports the device through the optionalIDeviceMetadataReporteruntil one report in the process succeeds, so a session that began before the server stored device metadata is described with no new sign-in; a refresh driven by an API 401 throughRenewRejectedAccessTokenAsyncdoes not report (SecureStoreTokenStorageService.cs:40-49,SecureStoreTokenStorageService.cs:141-144,SecureStoreTokenStorageService.cs:156-175; registered atMMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:80). - Each head wires its own trio in Program.cs. The WASM client registers
WasmTokenStorageServiceSameOriginProxyTokenRefresher+JwtAuthenticationStateProvider(MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web.Client/Program.cs:52-54,MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web.Client/Program.cs:51-53); the Blazor Server host's registrations live in the sharedAddMmcaBlazorWebHostboth consumer hosts call (above), which registersAddClientAuthSessionCookieSync, thenServerTokenStorageServiceviaAddCommonServerTokenStorage(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/DependencyInjection.cs:41,DependencyInjection.cs:50), then the same proxy refresher, thenAddCommonSameOriginApiProxy, which overrides that refresher withHandoffTokenRefresher, and last the auth-state provider (BlazorWebHostExtensions.cs:124,BlazorWebHostExtensions.cs:134,BlazorWebHostExtensions.cs:141,BlazorWebHostExtensions.cs:142,BlazorWebHostExtensions.cs:144); the MAUI host registers the shared SecureStorage-backed pair viaAddCommonMauiTokenStorageplusDirectApiTokenRefresher+JwtAuthenticationStateProvider(MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI/MauiProgram.cs:182-184,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI/MauiProgram.cs:135-137).
Rationale
- One application surface, three storage stories. Pages, services, and the HTTP pipeline talk to
ITokenStorageServiceandAuthenticationStateProvideronly; the head-specific choice of HttpOnly cookie versus SecureStorage lives entirely behind those abstractions and the Program.cs registration, so UI code never branches on render mode.ISecureTokenStoreis below that line again: only the MAUI freshness layer and the MAUI refresher consume it. - Keep the refresh token off the highest-risk surface. The browser heads are the ones with an XSS
attack surface, so their refresh token stays in an HttpOnly cookie and rotation happens server-side
through the same-origin proxy; the token the browser holds is memory-only and short-lived, and it is
only a claims-only copy, never the credential
(
SessionCookieEndpoints.cs:105-107,SameOriginProxyTransformer.cs:258-260). MAUI, with no DOM, can safely hold both tokens in the OS secure enclave. - Reuse the ADR-022 cookie plumbing rather than duplicate it. The browser refresher is a thin JS
interop call onto the same
/auth/session/tokenandDELETE /auth/session-cookieendpoints ADR-022 already stands up, so the client lifecycle adds no second server mechanism for reading or clearing the session. The same-origin API proxy adds the writers, the handoff endpoints and the proxy itself (SessionHandoffEndpoints.cs:19-20; ADR-131), so that the browser holds no credential at all. - Single-flight refresh avoids a token stampede. On a heavily-concurrent page (delegating handler, auth-state, SignalR all asking at once) the shared in-flight hydration means one network round-trip, not several racing refreshes.
Trade-offs
- The browser heads depend on the same-origin UI host.
SameOriginProxyTokenRefresheronly works where the UI host serves the/auth/session/*endpoints; a browser head deployed without that plumbing (ADR-022) cannot refresh. MAUI has no such dependency but pays for it with cross-origin direct token handling. - Client-side JWT parsing is advisory, not authoritative.
JwtAuthenticationStateProvidertrusts the token's shape and expiry for UI responsiveness and does no signature validation; the security boundary is the WebAPI, which validates every request. A tampered local token can flip anAuthorizeViewbut cannot pass an API call. - The MAUI raw store ships only from a MAUI-TFM package. All three storage services are
framework-owned and live in MMCA.Common.UI, the MAUI freshness layer included, so it is unit-tested
on the same path as the browser ones
(
MMCA.Common/Tests/Presentation/MMCA.Common.UI.Tests/Services/Auth/SecureStoreTokenStorageServiceTests.cs). Only the rawMauiSecureTokenStoredepends on the MAUISecureStorageAPI, so it lives inMMCA.Common.UI.Maui(MauiSecureTokenStore.cs:17-19), which is deliberately outsideMMCA.Common.slnx(the solution's Presentation folder listsMMCA.Common.API,MMCA.Common.Mcp,MMCA.Common.Grpc,MMCA.Common.UIandMMCA.Common.UI.Webbut not the MAUI package,MMCA.Common/MMCA.Common.slnx:23-29) and is built for android, ios, maccatalyst and windows on each framework version by a separate windows-only CI job (MMCA.Common/.github/workflows/ci.yml:254-259,ci.yml:260-264,ci.yml:299-301;MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/MMCA.Common.UI.Maui.csproj:18; ADR-042). A change to the raw MAUI store is therefore verified on a different, slower path than the rest. - The split multiplies the paths to keep correct. Three
ITokenStorageServiceimplementations, the MAUI-onlyISecureTokenStoreimplementation beneath one of them (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiSecureTokenStore.cs:22), two refreshers plus the proxy's handoff refresher, and two cookie-syncs, mean the same login/refresh/logout invariant is expressed in several places; each head's registration set must stay consistent or a head silently loses auth, and the MAUI head's storage registration is a pair rather than a single line.
Related
ADR-022 (the Blazor host's HttpOnly session cookie and the /auth/session/* endpoints the browser
refresher proxies through), ADR-050 (the single rotating refresh token with reuse detection that the
auth/refresh endpoint enforces and that this client lifecycle acquires against), ADR-042 (the
device-capability abstraction and the MAUI head whose SecureStorage backs DirectApiTokenRefresher
and the raw half of the shared storage pair, MauiSecureTokenStore in the MAUI-TFM package beneath
SecureStoreTokenStorageService in MMCA.Common.UI), ADR-131 (the same-origin API proxy whose handoff refresher, handoff cookie sync and
claims-only browser tokens replace the browser credential path on both consumer hosts).
Revision (2026-08-07)
The MAUI half of ITokenStorageService is no longer app-local. The original Decision left the
SecureStorage-backed implementation in each app because it depends on the MAUI SecureStorage API;
it has since been hoisted into the framework's MAUI-TFM package, so all three storage
implementations are now framework-owned.
- Framework-owned, in MMCA.Common.UI.Maui. Both tokens live under the
auth_access_token/auth_refresh_tokenkeys inSecureStorage.Default, in the sealed class the 2026-08-31 Revision below namesMauiSecureTokenStore(MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiSecureTokenStore.cs:22,MauiSecureTokenStore.cs:24-25). The per-app copies are gone: a workspace-wide search for the MAUI storage types returns only the framework files underMMCA.Common.UI.Maui, nothing underMMCA.ADC/Source/orMMCA.Store/Source/, so the "behavior can drift between the two apps" risk the Trade-offs section recorded no longer applies. - Both heads register it through one extension method.
AddCommonMauiTokenStorage()is the single call each MAUI host makes (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:97,MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI/MauiProgram.cs:163,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI/MauiProgram.cs:97). Its registrations are scoped, not singleton, to match the two browser siblings so component code depends on one lifetime on every head (DependencyInjection.cs:99-100, rationale atDependencyInjection.cs:92-95). The rest of each MAUI trio is unchanged:DirectApiTokenRefresher+JwtAuthenticationStateProviderstill follow it (MauiProgram.cs:164-165in ADC,MauiProgram.cs:98-99in Store). - The hoist added failure handling the app copies did not have. Every read and write is guarded,
because the OS invalidates keystore entries on its own schedule and the raw API then throws rather
than returning nothing: a failed read drops the unreadable entry and degrades to "no token stored"
(
MauiSecureTokenStore.cs:69-85), a failed write retries once against a freshly removed key and otherwise propagates (MauiSecureTokenStore.cs:91-104),ClearTokensAsyncis best-effort so logout always succeeds (MauiSecureTokenStore.cs:56-63,:107-120), andSetTokensAsyncwrites both tokens under one shared guard so either write failing drops both, rather than leaving a mismatched pair (MauiSecureTokenStore.cs:34-53). - What it cost. The classes cannot live in
MMCA.Common.UI(that package must stay Blazor-WASM-compatible and MAUI-free), so they sit inMMCA.Common.UI.Maui, outsideMMCA.Common.slnxand built across its four TFMs by a windows-only CI job (ADR-042). The Trade-offs bullet above is rewritten accordingly: the risk is no longer divergent copies, it is a slower and separate verification path for the one shared copy.
Revision (2026-08-14)
SetTokensAsync closed a gap the original hoist left open. Point 3 above previously described the
method as writing the refresh token first and dropping both tokens only when the following
access-token write failed, which left a window where a failing refresh-token write escaped before
the guard was entered and left the OLD pair in place: the app then held a stale access token it
believed was current until a manual sign-out cleared it.
SetTokensAsync performs both writes inside one try/catch, so either write failing drops both
tokens and forces a clean re-login instead of leaving a stale, partially-updated pair
(MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiSecureTokenStore.cs:34-53; the
comment at :36-39 records the trap). Point 3's description above is updated accordingly: read
guarding, write-retry, and best-effort clearing are all unchanged, only the SetTokensAsync behavior
narrowed.
Revision (2026-08-31)
MAUI storage is two classes, and the freshness check the browser heads always had is now on every head.
- A raw store beneath the storage service.
ISecureTokenStoreis the third abstraction: raw persistence, no freshness semantics, implemented only where a head persists tokens itself (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ISecureTokenStore.cs:16). The MAUI implementationMauiSecureTokenStoreholds every line ofSecureStorage.Defaulthandling and all the guarding the 2026-08-07 Revision describes (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiSecureTokenStore.cs:22);MauiTokenStorageServicekeeps theITokenStorageServicesurface and delegates the raw reads and writes to it (MauiTokenStorageService.cs:69,MauiTokenStorageService.cs:72-73,MauiTokenStorageService.cs:76). - The split is what keeps the graph acyclic. Storage depends on the refresher, and
DirectApiTokenRefresherdepends on the raw store rather than back on storage (DirectApiTokenRefresher.cs:18-20, rationale atDirectApiTokenRefresher.cs:10-16,ISecureTokenStore.cs:4-9). Depending onITokenStorageServicethere would let a refresh re-enter the acquisition that started it. - MAUI reads through an expiry check.
MauiTokenStorageServicerefreshes proactively when the stored token is within the same 30-second skew the browser services use, and collapses concurrent callers onto one in-flight acquisition (MauiTokenStorageService.cs:23,MauiTokenStorageService.cs:30-36,MauiTokenStorageService.cs:43-48). A token read back from the enclave can be hours or days old, so returning it verbatim handed the delegating handler, the auth-state provider and SignalR an expired bearer, which the user experienced as a random sign-out. - Registration is a pair, still one call.
AddCommonMauiTokenStorage()registers both the raw store and the storage service, both scoped (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:97,DependencyInjection.cs:99-100), so each MAUI host's wiring is unchanged (MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI/MauiProgram.cs:163-165,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI/MauiProgram.cs:97-99). Both halves are required: the storage service cannot resolve without a raw store behind it.
Revision (2026-10-01)
No decision or rationale changed. Citations in Decision and Trade-offs are re-anchored to the current
source (DirectApiTokenRefresher, JsFetchSessionCookieSync, mmca-auth-cookie.js,
AuthDelegatingHandler, the three storage services, both DependencyInjection.cs files, the ADC and
Store host Program.cs files, MMCA.Common.slnx and the windows MAUI job in ci.yml). Two statements
are corrected where they live. The Trade-offs bullet now lists all four projects in the slnx
Presentation folder (MMCA.Common/MMCA.Common.slnx:19-24), which never held only the two UI
packages. The bearer-handler bullet now records the SkipBearer request option: the MAUI refresh POST
goes through the same "APIClient" pipeline as every other call, so it opts out of the bearer header
and never reads the storage instance that is awaiting it, which is the HTTP-pipeline counterpart of
the raw-store split
(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthDelegatingHandler.cs:15-20,
AuthDelegatingHandler.cs:27-30, DirectApiTokenRefresher.cs:18-22, DirectApiTokenRefresher.cs:46).
Also previously unrecorded: SetTokensAsync on both browser storage services throws
InvalidOperationException when the session-cookie write reports failure, after the in-memory token
is set, so a login whose cookie was never written surfaces as an error rather than signing out at the
first access-token expiry (WasmTokenStorageService.cs:68-71, ServerTokenStorageService.cs:89-92).
Revision (2026-10-06)
No decision changed; four behaviors the Decision did not record are now stated where they live.
- The browser refresher tells "no session" from "unavailable".
SameOriginProxyTokenRefresherimplementsISessionAwareTokenRefresherand returns a three-wayTokenAcquisition; the script answersnullonly on a 401 and throws on any other non-OK status (SameOriginProxyTokenRefresher.cs:23-37,mmca-auth-cookie.js:51-56). The earlier wording ("returnsnullrather than throwing") now holds only for the collapsingAcquireAccessTokenAsync(SameOriginProxyTokenRefresher.cs:19-20). - Both browser storage services hold a 15-second anonymous grace, started only by a definitive
no-session answer and cleared by
SetTokensAsync(WasmTokenStorageService.cs:30,ServerTokenStorageService.cs:40). Each also gained a constructor taking aTimeProvider, with the original constructor kept (WasmTokenStorageService.cs:22-25,WasmTokenStorageService.cs:45). - The MAUI single-flight is process-wide, not per instance, so the handler scope and the
component scope cannot each rotate the same refresh token (
MauiTokenStorageService.cs:24-30,MauiTokenStorageService.cs:70-76). AuthDelegatingHandlerleaves a request that already carries anAuthorizationheader untouched, so a forced-refresh replay is not overwritten with the rejected stored token (AuthDelegatingHandler.cs:34).
All path:line anchors in Status, Decision and Trade-offs were re-verified against current source.
The MAUI registration cited in the 2026-08-07 and 2026-08-31 Revisions now sits at
MMCA.Common.UI.Maui/DependencyInjection.cs:103 and :105-106, the ADC MAUI wiring at
MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI/MauiProgram.cs:165-167, and the browser SetTokensAsync
throw at WasmTokenStorageService.cs:103-106 and ServerTokenStorageService.cs:131-134.
Revision (2026-10-07)
Re-verified against current source. The three abstractions, the shared bearer handler, the client-side auth-state provider and the MAUI storage story are unchanged. What moved is the browser credential path on the same-origin API proxy hosts, which the Decision attributed to the default refresher and cookie sync: there the browser holds only a claims-only token and the handoff endpoints plus the proxy are a second server mechanism, so the Rationale bullets on the browser token and on reusing the ADR-022 plumbing are qualified accordingly. Two MAUI refresher outcomes the Decision did not record are also stated.
- The Server circuit uses the protected handoff on both consumer hosts.
AddCommonSameOriginApiProxyreplacesITokenRefresherwithHandoffTokenRefresherandISessionCookieSyncwithHandoffSessionCookieSync(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyServiceExtensions.cs:83-84), and both hosts call it after their own registrations (MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:161,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:153). The page carries onlySessionHandoffProtectorciphertext (HandoffSessionServices.cs:24,HandoffSessionServices.cs:58,mmca-auth-cookie.js:66-100,SessionHandoffEndpoints.cs:17-18), so the circuit'smmcaAuthSession.getTokenandmmcaAuthCookie.setpaths are not used there, and boot fails if a later registration displaces either (SameOriginApiProxyEndpointExtensions.cs:64-92). ADR-131 is now cross-referenced in Related. - Claims-only browser tokens. Under the proxy
/auth/session/tokenreturns an unsigned claims copy (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:75-77as recorded then; since v1.331.0 it is the only answer, and no browser seed endpoint exists, Revision 2026-12-03), and WASM sign-in cookies are written by the proxy'sTokenIssuingrewrite, which emptiesrefreshTokenin the body (SameOriginProxyTransformer.cs:122-144). - The WASM bearer is stripped and re-stamped. A WASM client of a proxy host points
"APIClient"at the proxy and adds an innermost handler that stripsAuthorization(MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:120-121,DependencyInjection.cs:136,DependencyInjection.cs:149-155); the proxy stamps the cookie session's bearer server-side (SameOriginApiProxyEndpoint.cs:86-95,SameOriginProxyTransformer.cs:60). - MAUI refresher outcomes.
DirectApiTokenRefresheris a sealedISessionAwareTokenRefresher(DirectApiTokenRefresher.cs:35-37). A 409 (Auth.RefreshSuperseded) is transient and never clears the stored pair (DirectApiTokenRefresher.cs:25-33,DirectApiTokenRefresher.cs:64-67,DirectApiTokenRefresher.cs:88-98); any other non-success status is no session (DirectApiTokenRefresher.cs:69-72); MAUI storage hydrates through the collapsing overload, so an unavailable result reaches callers as anullbearer (MauiTokenStorageService.cs:103-104). - Anchors re-verified against current source:
DirectApiTokenRefresher.cs:48-49(reads),:56-62(POST),:61(SkipBearer),:80(persist),:12-18(raw-store rationale); the ADC Server host atMMCA.ADC.UI.Web/Program.cs:150-151and:163; the windows MAUI job atMMCA.Common/.github/workflows/ci.yml:173-178,:179-182and:214-216(the MAUI build step, formerly cited at:239-241, moved up when lines above it were removed). TheMauiTokenStorageServicedelegation the 2026-08-31 Revision cites now sits atMauiTokenStorageService.cs:94,:97-98and:101.
Revision (2026-10-21)
Re-verified against current source. The three abstractions, the head-specific trios, the same-origin
proxy handoff, the claims-only browser token, the 15-second grace, the 30-second skew and the
single-flight refresh are unchanged. What moved is how the MAUI refresher classifies failures, how
the Server storage service tells the circuit from the prerender, and two behaviors the Decision did
not record. The Decision anchors that drifted are re-pointed (point 6); the MAUI storage, Server
host and client Program.cs anchors had not moved and stand as written. The dated
Revisions above keep their anchors as written; they are not current.
- MAUI refresher: a refusal is "no session", other failures are unavailable.
DirectApiTokenRefresheranswers no session for a 400, 401 or 403 and unavailable for every other non-success status, a dropped connection and anHttpClienttimeout the caller did not request (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/DirectApiTokenRefresher.cs:91-96,DirectApiTokenRefresher.cs:74-82, rationale atDirectApiTokenRefresher.cs:34-39). It also answers no session when no pair is stored and when a success body carries an empty access token (DirectApiTokenRefresher.cs:57-60,DirectApiTokenRefresher.cs:98-102). The Decision bullet is corrected in place; point 4 of the 2026-10-07 Revision ("any other non-success status is no session") no longer holds. - Server storage: the circuit has an
HttpContext. It is the request that opened the hub connection, so a non-nullHttpContextalone does not mean prerender:ServerTokenStorageServiceanswers from memory when there is noHttpContextor memory has become authoritative, and otherwise lets a hub-connection request use its cookie only while that token is fresh or absent (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Services/ServerTokenStorageService.cs:26-36,ServerTokenStorageService.cs:74,ServerTokenStorageService.cs:227-250,ServerTokenStorageService.cs:257-259). Its refresh-token read returns the cookie whenever anHttpContextis present, including that connection request on the circuit (ServerTokenStorageService.cs:140-145). - A hydrate overtaken by a login or logout is discarded. Both browser storage services carry a
token-version counter that
SetTokensAsyncandClearTokensAsyncbump; a hydrate that sees it move returns the current token instead of its stale answer and starts no grace (WasmTokenStorageService.cs:44,WasmTokenStorageService.cs:141,WasmTokenStorageService.cs:155,ServerTokenStorageService.cs:68,ServerTokenStorageService.cs:191,ServerTokenStorageService.cs:205-208). - The bearer handler marks replay safety.
AuthDelegatingHandlercatches anHttpRequestException, records on it whether the request may be resent, and rethrows (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthDelegatingHandler.cs:26-41). - What starts the anonymous grace. A
nullfrom the refresher starts it unless a session-aware refresher reports the result unavailable; a plainITokenRefresher'snullcounts as no session (WasmTokenStorageService.cs:144-153,ServerTokenStorageService.cs:194-203). The Decision bullet, which said only a session-awareNoSessionstarts it, is corrected in place. - Anchors re-verified against current source:
ITokenRefresher.cs:17and:24;DirectApiTokenRefresher.cs:41-43(class),:54-55(reads),:62-67(POST),:67(SkipBearer),:86-89and:112-122(409),:104(persist);AuthDelegatingHandler.cs:15,:23,:10-13,:47-50,:52,:54,:57;MMCA.Common.UI/DependencyInjection.cs:122,:132,:154(handler),:128-129,:144,:157-163(proxy strip),:251and:253(cookie sync);WasmTokenStorageService.cs:57-96,:64-67,:73-78,:99,:101-115,:105,:162-165;ServerTokenStorageService.cs:44,:51,:54,:93-138,:106-109,:115-120,:151,:214-217; the MAUI wiring atMMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI/MauiProgram.cs:171-173andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI/MauiProgram.cs:103-105.ISecureTokenStorestill has one implementer (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiSecureTokenStore.cs:22).
Revision (2026-10-26)
Re-verified against current source. The three abstractions, the head-specific trios, the
same-origin proxy handoff, the claims-only browser token, the 15-second grace, the 30-second skew,
the token-version counter and the single-flight refresh are unchanged. What the Decision did not
record is how a session that ends on the server reaches the UI, and the WASM boot warm-up; both are
now stated in place. Every Decision anchor into the two browser storage services, the auth-state
provider, the auth script, the session-cookie endpoints, the proxy endpoint and the Server host
Program.cs files had moved and is re-pointed (point 4). The dated Revisions above keep their
anchors as written; they are not current (the 2026-10-21 note that the Server host anchors had not
moved no longer holds).
- A session ended on the server signs the shell out.
ISessionAwareTokenStorageextendsITokenStorageServicewith aSessionEndedevent, raised once when a session-aware refresher answers a definitive "no session" for a session the storage held, and never on a transient failure (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ISessionAwareTokenStorage.cs:12,ISessionAwareTokenStorage.cs:18). Both browser storage services implement it (WasmTokenStorageService.cs:29,:58, raised at:191-197;MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Services/ServerTokenStorageService.cs:52,:87, raised at:244-249).JwtAuthenticationStateProvidersubscribes rather than implements: on the event it clears the optionalIUiReadCacheand callsNotifyUserLogout(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/JwtAuthenticationStateProvider.cs:44,:51-54,:114-118).MauiTokenStorageServiceimplements onlyITokenStorageService, so the MAUI head has no such path (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiTokenStorageService.cs:34). - The Server storage marks a session held from the connection cookie. A hub-connection request
whose cookie carries a token sets the held flag before answering, so a circuit that started signed
in can later raise
SessionEnded(ServerTokenStorageService.cs:282-285). - WASM boot pre-hydrates the token.
TokenHydrationWarmup.WarmAsyncreads the access token once throughITokenStorageServiceand swallows any failure; both WASM clients start it afterbuilder.Build()and discard the task (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/TokenHydrationWarmup.cs:26,TokenHydrationWarmup.cs:37-58,MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web.Client/Program.cs:92,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web.Client/Program.cs:80). - Anchors re-verified against current source:
mmca-auth-cookie.js:47-63(getToken),:54-59(401 versus throw),:69-103(mmcaAuthHandoff),:10-23(mmcaAuthCookie.set);WasmTokenStorageService.cs:26(class),:31(skew),:34(grace),:48(version),:71-110(read, grace check:78-81, single flight:87-92),:113(null refresh token),:115-130(SetTokensAsync, bump:118, grace cleared:119),:134and:145(clear bumps),:159-173,:175-178and:182-185(hydrate);ServerTokenStorageService.cs:29-39(remarks),:47(class),:54,:57,:71,:77,:106-151(read, grace:119-122, single flight:128-133),:153-160(refresh-token read),:165,:166,:182,:196(bumps and grace clear),:200-253(hydrate, version check:226-229),:260-288(TryAnswerFromCookie),:295-297(IsHubConnection);JwtAuthenticationStateProvider.cs:20,:62-93,:79,:89-92,:99,:111;SessionCookieEndpoints.cs:41and:55(claims-only POST answers 204),:83-86(claims-only token);SameOriginApiProxyEndpoint.cs:96-111(bearer from the cookie session); the Server hosts atMMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:156-157,:167,:169,:290andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:148-149,:159,:161,:268.SessionClaimsToken.cs:10and:17andSameOriginProxyTransformer.cs:60stand as written.
Revision (2026-10-28)
Re-verified against current source. The head-specific trios, the same-origin proxy handoff and the
override order are unchanged: in both Server hosts AddCommonSameOriginApiProxy still follows the
SameOriginProxyTokenRefresher registration and precedes the auth-state provider, and the call still
replaces ITokenRefresher with HandoffTokenRefresher and ISessionCookieSync with
HandoffSessionCookieSync
(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyServiceExtensions.cs:83-84).
Only the Server host Program.cs anchors moved, each by one line, and the Decision is re-pointed in
place. The dated Revisions above keep their anchors as written.
- Anchors re-verified against current source:
MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:157(AddCommonServerTokenStorage),:158(SameOriginProxyTokenRefresher),:168(AddCommonSameOriginApiProxy),:170(JwtAuthenticationStateProvider),:291(MapCommonSameOriginApiProxy);MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:149,:150,:160,:162,:269(same order).
Revision (2026-11-23)
Re-verified against current source. The three abstractions, the browser trios, the same-origin proxy
handoff, the claims-only browser token, the 15-second grace, the 30-second skew, the token-version
counter, the MAUI refresher's 409 and refusal rules and the single-flight refresh are unchanged. What
moved is where the MAUI freshness layer lives and how a session ends: the MAUI layer is now
SecureStoreTokenStorageService in MMCA.Common.UI and is session-aware, an API 401 now drives a
refresh, and the Server host wiring sits in the shared web host. The Decision, Rationale,
Trade-offs and Related are corrected in place. The dated Revisions above keep their anchors and
type names as written; their MauiTokenStorageService, IUiReadCache and "no MAUI equivalent"
statements are not current.
- The MAUI freshness layer is in MMCA.Common.UI.
SecureStoreTokenStorageServicesits overISecureTokenStore(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/SecureStoreTokenStorageService.cs:55-59); only the rawMauiSecureTokenStorestays inMMCA.Common.UI.Maui(MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/Services/MauiSecureTokenStore.cs:17-22), andAddCommonMauiTokenStorageregisters the pair (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:115,:117-118). The layer is unit-tested on the slnx path (MMCA.Common/Tests/Presentation/MMCA.Common.UI.Tests/Services/Auth/SecureStoreTokenStorageServiceTests.cs), so only the raw store is on the windows-only build path, andISecureTokenStoreis consumed by that layer as well as byDirectApiTokenRefresher. - The MAUI head has a
SessionEndedpath. The MAUI storage implementsISessionAwareTokenStoragewith a process-wide event and a static token version (SecureStoreTokenStorageService.cs:59,:74,:76,:81-110). Its hydrate takes the session-awareTryAcquireAccessTokenAsync(:261; the collapsing call only for a refresher that is not session-aware,:251-256): unavailable still yields anullbearer (:262-264), and a definitive "no session" for a held pair clears the pair and raisesSessionEnded(:274-276). - An API 401 can end a session.
ISessionAwareTokenStoragealso declaresRenewRejectedAccessTokenAsync, a no-op by default (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/Tokens/ISessionAwareTokenStorage.cs:20-37), implemented by all three storages (WasmTokenStorageService.cs:118-137,ServerTokenStorageService.cs:163-192,SecureStoreTokenStorageService.cs:156-175).AuthDelegatingHandlerreports every 401 to a request that carried a bearer to the storage that owns that token, except a token that renewal produced, which it never re-reports; the storage's token comparison and its single-flight are what collapse repeated reports of one token into one refresh (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthDelegatingHandler.cs:20-34,:205-208,:310-341); a 403 carrying the multi-factor-required code raisesMultiFactorRequiredSignal(:209-212,:231-252). - The auth-state provider forgets list-page state.
IUiReadCacheno longer exists; the one constructor takes an optionalListPageStateService, andOnSessionEndedforgets that state and callsNotifyUserLogout(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/JwtAuthenticationStateProvider.cs:41-54,:145-151). - The Server host wiring is in the shared web host. Neither consumer
Program.csregisters the token services itself; both callAddMmcaBlazorWebHostandUseMmcaBlazorWebPipeline(MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:26,:128on net11.0,:130on net10.0;MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:30,:92), which register the cookie sync, the Server storage, the proxy refresher, the same-origin API proxy and then the auth-state provider, and map the proxy (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hosting/BlazorWebHostExtensions.cs:124,:134,:141,:142,:144,:210). The override order is unchanged. - MAUI refresh backfills device metadata. After a stale-token refresh in
GetAccessTokenAsyncthat produced a token (not a 401-driven renewal), the MAUI storage reports the device once per process through the optionalIDeviceMetadataReporter(SecureStoreTokenStorageService.cs:40-49,:141-144; registered atMMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/DependencyInjection.cs:80). - The MAUI package builds eight framework targets. The project targets android, ios,
maccatalyst and windows for each entry of
MmcaNetVersions(net10.0;net11.0), not four TFMs (MMCA.Common/Source/Presentation/MMCA.Common.UI.Maui/MMCA.Common.UI.Maui.csproj:18,MMCA.Common/build/Frameworks.props:23). - Anchors re-verified against current source:
DirectApiTokenRefresher.cs:40-42,:53-54,:61-66(SkipBearer:66),:103,:25-32,:85-88,:111-121,:90-95,:33-38,:73-81,:56-59,:98-101,:12-17;WasmTokenStorageService.cs:140(null refresh token),:142-157(SetTokensAsync, bump:145, grace cleared:146),:161and:172(clear bumps),:196-247(hydrate, version check:222-225, grace:229-232, raise:238-244);ServerTokenStorageService.cs:29-41,:48,:53,:55,:58,:72,:78,:88,:107-152(grace:120-123, single flight:129-134),:194-201,:206,:207,:224,:238,:265-318(version check:291-294, raise:309-315),:325-353(held flag:347-350),:360-362;SecureStoreTokenStorageService.cs:61(skew),:63-67(single flight),:31-39(process-wide rationale),:115-116(raw read first);AuthDelegatingHandler.cs:36,:44,:187-190,:192,:194,:197,:131-141,:12-18;JwtAuthenticationStateProvider.cs:24,:61-94,:78,:89-93,:100,:112;MMCA.Common.UI/DependencyInjection.cs:140,:150,:172,:146-147,:162,:175-181,:289,:291;SessionCookieEndpoints.cs:93-96(claims-only token;:41and:55stand);SameOriginProxyTransformer.cs:113-116,:133-148,:256-258,:77;SameOriginApiProxyEndpoint.cs:99-113; the WASM clients atMMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web.Client/Program.cs:51-53,:55,:95andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web.Client/Program.cs:52-54,:56,:87; the MAUI hosts atMMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI/MauiProgram.cs:182-184andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI/MauiProgram.cs:135-137;MMCA.Common.slnx:23-29;ci.yml:254-259,:260-264,:299-301.
Revision (2026-12-03)
MMCA.Common v1.331.0. No decision changed; the browser cookie bullets are restated to match the source.
- The server is the only writer of the browser cookies. No endpoint takes a token from the
browser (
MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:16-18).JsFetchSessionCookieSync.SyncAsyncwrites nothing and reports success (MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/JsFetchSessionCookieSync.cs:24); the cookies are written by the proxy'sTokenIssuingrewrite (SameOriginProxyTransformer.cs:258-260) and the Server circuit's protected handoff (SessionHandoffEndpoints.cs:73), and cleared byDELETE /auth/session-cookie(ADR-022). The Decision bullet "Login seeds the browser HttpOnly cookie through a JS fetch" is replaced by "The server writes the browser HttpOnly cookies; the browser only clears them". - Claims-only is the only mode.
/auth/session/tokenalways answers aSessionClaimsToken(SessionCookieEndpoints.cs:105-107); there is no setting that switches it, so the Server-host bullet no longer names one, and the two Rationale bullets on the browser token and the ADR-022 plumbing are restated to match (SessionCookieEndpoints.cs:105-107). Its handoff anchors are refreshed (SameOriginApiProxyServiceExtensions.cs:79-80,HandoffSessionServices.cs:25,:31-35,:59,SessionHandoffEndpoints.cs:19-20).