davidortinau/maui-skills/maui-authentication
Claude Code and agent skill by davidortinau/maui-skills
- community
Checking that the SKILL.md file is still in the repository.
Add authentication to .NET MAUI apps. Covers WebAuthenticator for generic OAuth 2.0 / social login, and MSAL.NET for Microsoft Entra ID (Azure AD) with broker support (Microsoft Authenticator), token caching, Conditional Access, platform-specific setup (Android, iOS, Windows), DelegatingHandler for bearer token API calls, and Blazor Hybrid integration. USE FOR: "add authentication", "OAuth login", "MSAL.NET", "social login", "WebAuthenticator", "Entra ID MAUI", "Azure AD login", "Google login MAUI", "Apple login MAUI", "token caching", "bearer token", "sign in". DO NOT USE FOR: secure local storage of tokens (use maui-secure-storage), Aspire-specific auth setup (use maui-aspire), or server-side Entra ID provisioning (use entra-id-aspire-provisioning).
Install
npx vskill@latest install davidortinau/maui-skills/maui-authenticationSKILL.md
.NET MAUI Authentication
Security: Never Embed Secrets
❌ Never embed client secrets, API keys, or signing keys in a mobile app binary. They can be extracted trivially via decompilation.
The correct pattern:
- App calls
WebAuthenticatorpointing to your server endpoint - Server initiates the OAuth flow with the identity provider (holds the client secret)
- Provider redirects back to your server with an auth code
- Server exchanges the code for tokens and returns them to the app via the callback URI
WebAuthenticator Gotchas
⚠️ Windows WebAuthenticator is broken
Windows WebAuthenticator is currently broken. See dotnet/maui#2702. Use MSAL or a WinUI-specific workaround for Windows auth flows.
⚠️ Apple Sign In returns name/email only once
Apple only returns the user's name and email on the first sign-in. Cache them immediately — subsequent sign-ins won't include them.
⚠️ PrefersEphemeralWebBrowserSession
Set to true on iOS 13+ to force a fresh login prompt. When false (default), the auth session shares cookies with Safari — the user may be auto-logged in, which can confuse logout/switch-account flows.
⚠️ Callback URI mismatches
The most common auth failure is a URI scheme mismatch. The CallbackUrl in code must exactly match:
- Android:
DataScheme+DataHostin theIntentFilter - iOS:
CFBundleURLSchemesinInfo.plist - Windows:
Protocol NameinPackage.appxmanifest
WebAuthenticator Checklist
- [ ] Callback URI scheme matches across all platform configs and
CallbackUrl - [ ] Android has
WebAuthenticatorCallbackActivitywith correctIntentFilter - [ ] Android 11+ has
<queries>for Custom Tabs in the manifest - [ ] iOS/Mac Catalyst has
CFBundleURLTypesinInfo.plist - [ ] Client secrets are on the server, not in the app
- [ ] Tokens stored with
SecureStorage, cleared on logout - [ ]
TaskCanceledExceptionhandled gracefully in UI
Choosing Between WebAuthenticator and MSAL.NET
| Criteria | WebAuthenticator | MSAL.NET | |
|---|---|---|---|
| Identity provider | Any OAuth 2.0 / OIDC | Microsoft Entra ID | |
| Broker support (SSO) | ❌ No | ✅ Microsoft Authenticator, Company Portal | |
| Conditional Access / MFA | ❌ Manual | ✅ Built-in | |
| Token cache & refresh | ❌ Manual (SecureStorage) | ✅ Automatic | |
| Complexity | Simple | More setup | |
| Use when | Google, Apple, generic OIDC | Entra ID / Azure AD, Microsoft Graph |
MSAL.NET Gotchas
⚠️ Android: OnActivityResult is required
Forgetting AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs in MainActivity.OnActivityResult causes auth to hang silently after the browser returns.
⚠️ iOS: Keychain sharing is required
Without Entitlements.plist containing keychain group com.microsoft.adalcache, token caching fails silently and users are prompted to sign in every time.
⚠️ Handle MsalUiRequiredException
When AcquireTokenSilent throws MsalUiRequiredException, the cached token is expired and interaction is needed. Always fall back to AcquireTokenInteractive.
⚠️ Handle user cancellation gracefully
⚠️ Blazor Hybrid: Auth happens at the MAUI layer
In MAUI Blazor Hybrid apps, authentication must happen at the MAUI layer (MSAL.NET), not in the Blazor WebView. Don't use AddMicrosoftIdentityWebApp or server-side OIDC patterns. Instead:
- MAUI handles sign-in via
IAuthService(MSAL.NET) - A custom
MsalAuthenticationStateProviderexposes auth state to Blazor HttpClientwithDelegatingHandlerattaches bearer tokens automatically
MSAL.NET Checklist
- [ ]
Microsoft.Identity.ClientNuGet package added - [ ] App registration created in Entra ID with correct redirect URIs
- [ ]
AuthConfig/appsettings.jsonhas ClientId, TenantId, Scopes - [ ] Android:
AndroidManifest.xmlhas<queries>for broker and browsers - [ ] Android:
MainActivity.OnActivityResultcallsAuthenticationContinuationHelper - [ ] iOS:
Info.plisthasCFBundleURLSchemeswithmsauth.{BundleId} - [ ] iOS:
Entitlements.plisthas keychain groupcom.microsoft.adalcache - [ ] iOS:
AppDelegate.OpenUrlcallsAuthenticationContinuationHelper - [ ]
IAuthServiceregistered as singleton in DI - [ ]
DelegatingHandlerattached toHttpClientfor API calls - [ ] Login/logout UI wired up
- [ ]
MsalUiRequiredExceptionhandled (triggers interactive sign-in) - [ ]
MsalClientExceptionwithauthentication_canceledhandled gracefully
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/maui-skills/skills/maui-authentication/SKILL.md
Popularity
- Repository stars
- 96
- Repository forks
- 14
- 7-day trend score
- 23
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 22 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/davidortinau/maui-skills/maui-authentication)