Skip to content

feat(msal): platform-correct sign-in, storage defaults and sign-out, tested against a stub tenant - #3161

Merged
kazo0 merged 3 commits into
mainfrom
msal-2-runtime-dispatch
Aug 25, 2026
Merged

kazo0 merged 3 commits into
mainfrom
msal-2-runtime-dispatch

Conversation

@kazo0

@kazo0 kazo0 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #3157 (layer 2/4 of #3155; relates to #3025, #2438, #2346)

Stack 2/4 — base: msal-1-ci-lanes. Review only this layer's diff. Depends on layer 1 for the device lanes that run its tests. Deliberately deferred upward: WebAssembly token-cache persistence (layer 3) and the Uno version floor (layer 4).

PR Type

  • Bugfix
  • Feature

What is the current behavior?

  • Skia Android/iOS — AddMsal registers nothing. Uno.Sdk substitutes the plain netX.0 build of the provider on those heads, and that build was a stub (UNO_EXT_MSAL undefined), so every auth call fails with "No providers specified". The consumer-side Package.targets gated the define on repo-internal properties that are empty in apps, so apps got the define on every TFM including the stubbed ones.
  • Mac Catalyst — AddMsal returns silently and fails the same way, much later.
  • Android, iOS, desktop — no redirect URI is applied; apps hand-write an #if ANDROID / #elif IOS / #else block to sign in.
  • macOS and Linux desktop — MsalCacheHelper.CreateAsync throws ArgumentNullException (MsalAuthenticationProvider does not work on MacOS out of the box #3025): SetupStorage supplies no keychain/keyring properties. Caught, logged, no fallback.
  • Everywhere — a failed silent refresh is reported as success (empty access token); sign-out removes only the first account; LoginAsync re-wraps MSAL exceptions and loses the type; the per-request interactive modifiers (WithPrompt, WithLoginHint, WithCustomWebUi, …) are unreachable from the public surface. And none of it has a test.

What is the new behavior?

Platform selection is runtime dispatch (OperatingSystem.Is*, with IsMacCatalyst() excluded from the iOS path), so the substituted plain-TFM assembly behaves correctly on Skia mobile. UNO_EXT_MSAL is defined for every platform that ships a functional provider and Package.targets applies the same allow-list in consuming projects. Mac Catalyst throws PlatformNotSupportedException at registration.

Redirect URIs are derived per platform — msal{ClientId}://auth, msauth.{BundleId}://auth, the WebAuthenticationBroker URI, WithDefaultRedirectUri() — with documented precedence: platform default < configuration < the app's Builder(...) callback, which now runs after WithUnoHelpers() so it wins everywhere (it used to be overwritten on WebAssembly). UseDefaultPlatformRedirectUri = false opts out.

Token-cache persistence is platform-aware: MsalStorageDefaults supplies the keychain/keyring properties (configurable), mobile lets MSAL persist natively, and an opt-in AllowUnprotectedTokenCacheFallback keeps sign-in state on a machine with no secure store. Microsoft.Identity.Client moves to 4.87.0 for macOS desktop under .NET 10.

Lifecycle: sign-out removes every account; a refresh that cannot renew the session returns no tokens (the service, from #3152, then signs out) while a transient failure keeps them; the 5-minute interactive timeout defaults only on desktop; MSAL exceptions are rethrown untouched. Additive API: IMsalAuthenticationBuilder.InteractiveBuilder(...).

Tests. Uno.Extensions.Authentication.MSAL.Tests (unit, linked sources): redirect derivation and precedence, storage defaults. Uno.Extensions.Authentication.MSAL.UI.Tests: StubEntra fakes the tenant at the HTTP layer and StubWebUi the browser, so login → cache → silent refresh → rejected refresh → transient refresh → sign-out → cancellation all run through real MSAL (PKCE, code redemption, cache writes) with no network and no human. The device lanes now run this namespace. The vendored Microsoft.Identity.Client.Extensions.Msal/*.wasm.cs stubs were dead code and are removed; TestHarness drops its hard-coded redirect that the provider now honours.

Behaviour changes (documented in UpdatingExtensions.md)

Catalyst AddMsal throws; the app's Builder(...) wins over the platform default and WithUnoHelpers(); unrenewable refresh signs out; sign-out removes all accounts; exceptions untouched; desktop-only timeout default.

PR Checklist

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template
  • Unit Tests and/or UI Tests for the changes have been added
  • Wasm UI Tests are not showing any unexpected differences
  • Contains NO breaking changes — see the behaviour changes above
  • Updated the Release Notes
  • Associated with an issue (GitHub or internal)

Other information

Verified locally: MSAL.Tests 27/27; package surface builds warning-free on all seven TFMs; desktop runtime suite 13 MSAL + 8 storage = 21/21. Every bug fix has a test that was red before it (recorded in specs/012 and specs/010 — 012 because main took 009 for the hot-reload route refresh while this stack was open). Still open in spec 010: live on-device validation of the Skia-mobile fix — the runtime-test heads use ProjectReference, so the SDK's substitution never fires in CI.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH

@kazo0
kazo0 force-pushed the msal-2-runtime-dispatch branch from 321e95e to cd93b02 Compare August 25, 2026 01:17
@kazo0
kazo0 force-pushed the msal-2-runtime-dispatch branch from cd93b02 to 6bd8024 Compare August 25, 2026 01:25
@kazo0
kazo0 force-pushed the msal-2-runtime-dispatch branch 2 times, most recently from 648fbd8 to b254a52 Compare August 25, 2026 15:37
@kazo0
kazo0 force-pushed the msal-2-runtime-dispatch branch from b254a52 to b21e80e Compare August 25, 2026 15:38
Base automatically changed from msal-1-ci-lanes to main August 25, 2026 16:37
kazo0 and others added 2 commits August 25, 2026 12:37
…tested against a stub tenant

Layer 2/4 of the MSAL authentication work (#3139): the provider fixes and the
unattended test harness. No WebAssembly token-cache persistence yet - that is
the next layer.

- Platform selection is runtime dispatch (OperatingSystem.Is*), not #if: on
  Skia Android/iOS heads Uno.Sdk substitutes the plain netX.0 build of this
  assembly, and that build was a stub, so AddMsal registered nothing and every
  auth call failed with "No providers specified". UNO_EXT_MSAL is now defined
  for every platform that ships a functional provider (Package.targets applies
  the same rule in consuming projects); only Mac Catalyst keeps a stub, and
  AddMsal throws PlatformNotSupportedException there instead of failing later
- Redirect URIs are derived per platform - msal{ClientId}://auth on Android,
  msauth.{BundleId}://auth on iOS, the WebAuthenticationBroker URI on
  WebAssembly, WithDefaultRedirectUri() on desktop - with the documented
  precedence: platform default < configuration < the app's Builder callback,
  which now runs after WithUnoHelpers() so it wins everywhere
- Token-cache persistence is platform-aware: MsalStorageDefaults supplies the
  keychain (macOS) and keyring (Linux) properties MsalCacheHelper needs, so it
  no longer throws ArgumentNullException there (#3025); mobile lets MSAL
  persist natively; an opt-in AllowUnprotectedTokenCacheFallback keeps sign-in
  state on a machine with no secure store. Microsoft.Identity.Client moves to
  4.87.0 for macOS desktop under .NET 10 (4.72.1's IsMac() did not recognise
  the marketing-string OS description)
- Sign-out removes every account, not just the first; a refresh that cannot
  renew the session returns no tokens (the service signs out), while a
  transient failure keeps them; the 5-minute interactive timeout defaults only
  on desktop; MSAL exceptions are rethrown untouched; IMsalAuthenticationBuilder
  gains InteractiveBuilder(...) for the per-request modifiers
- The vendored Microsoft.Identity.Client.Extensions.Msal *.wasm.cs stubs were
  dead code and are gone

Tests: Uno.Extensions.Authentication.MSAL.Tests (unit, linked sources) covers
redirect derivation and precedence and the storage defaults;
Uno.Extensions.Authentication.MSAL.UI.Tests drives login, silent refresh,
rejected and transient refreshes, sign-out and cancellation through real MSAL
against StubEntra (a stubbed tenant at the HTTP layer) and StubWebUi, with no
network and no human. The device lanes now run that namespace too.
TestHarness drops its hard-coded uno-extensions://auth redirect, which the
provider used to override on WebAssembly and now would not.

Docs: redirect URIs, the Android/iOS callback plumbing, InteractiveBuilder,
the interactive timeout and the storage options in the how-to; the behavior
changes in UpdatingExtensions.md. Specs 009 and 010 carry the design trail.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH
MSAL keeps its token cache in the iOS keychain under com.microsoft.adalcache,
and iOS only grants an app the groups its entitlements name. The single-project
template ships Platforms/iOS/Entitlements.plist with an empty dict, so the first
token save after a successful sign-in fails with missing_entitlements (or, on
some MSAL versions, cannot_access_publisher_keychain while the PCA is built).
Nothing in the how-to said so: the iOS section stopped at the callback scheme,
and the platform table's "handled natively by MSAL" reads as nothing-to-do.

Step 5 now covers iOS platform setup rather than the callback alone, with the
two-entry array (bundle group first, so it stays the default access group for
items written without one), the errors it fixes, the provisioning-profile
difference between development and distribution, and the Builder(...) callback
as the only way to change the group - there is no configuration key, since the
Msal section binds to PublicClientApplicationOptions.

The storage entitlements how-to prescribed only the bundle group, which does
not satisfy MSAL; it now points here, and notes that single-project apps do not
need the manual CodesignEntitlements property.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y2fPT3jMCkGrVjMv3zmqb3
@kazo0
kazo0 force-pushed the msal-2-runtime-dispatch branch from b21e80e to 19872e9 Compare August 25, 2026 16:37
…ubs in the builder

Review follow-ups on #3161.

- MsalStorageDefaults.ApplyDefaults took (isMacOS, isLinux); both could be
  true by mistake and macOS silently won. MsalSecureStore { None, MacKeychain,
  LinuxKeyring } makes the choice one value, and ForCurrentOS() is the only
  place that maps OperatingSystem.Is*() to it
- Builder, InteractiveBuilder, Storage and Scopes kept a `#if !UNO_EXT_MSAL
  return builder;` stub. That build only exists for Mac Catalyst, where
  AddMsal throws PlatformNotSupportedException before the configure callback
  can run, so the stubs were unreachable; the real bodies compile on every
  TFM, so the branches are gone rather than made to throw

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH
@kazo0
kazo0 merged commit 1f8aa59 into main Aug 25, 2026
26 of 27 checks passed
@kazo0
kazo0 deleted the msal-2-runtime-dispatch branch August 25, 2026 17:24
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.

MSAL: platform-correct sign-in, storage defaults and sign-out, with an unattended test harness

3 participants