|
| 1 | +# DemoApp — Maui.CredentialManagers |
| 2 | + |
| 3 | +A .NET MAUI Blazor app demonstrating the [`Maui.CredentialManagers`](../../src/Maui.CredentialManagers) library. |
| 4 | +Targets `net10.0-android` and `net10.0-ios`. |
| 5 | + |
| 6 | +## Features demonstrated |
| 7 | + |
| 8 | +- Save password credentials (Credential Manager on Android, Keychain on iOS) |
| 9 | +- Retrieve password credentials (with optional auto-select and filtering) |
| 10 | +- SSO login via Google, Apple, or PlatformDefault (Google on Android, Apple on iOS) |
| 11 | +- Clear credential state |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- .NET 10 SDK |
| 16 | +- MAUI workload (`dotnet workload install maui`) |
| 17 | +- **Android**: Android SDK with API 24+ |
| 18 | +- **iOS**: Xcode with iOS 16.0+ SDK |
| 19 | + |
| 20 | +## Configuration |
| 21 | + |
| 22 | +All SSO options are set in [`MauiProgram.cs`](MauiProgram.cs) via `AddCredentialManagerService`: |
| 23 | + |
| 24 | +```csharp |
| 25 | +builder.Services.AddCredentialManagerService(options => |
| 26 | +{ |
| 27 | + options.GoogleServerClientId = "your-google-web-client-id"; |
| 28 | + // options.GoogleIosClientId = "your-google-ios-client-id"; |
| 29 | + // options.GoogleIosRedirectUri = "your-redirect-uri"; |
| 30 | + // options.AppleServiceId = "your-apple-service-id"; |
| 31 | + // options.AppleRedirectUri = "your-apple-redirect-uri"; |
| 32 | +}); |
| 33 | +``` |
| 34 | + |
| 35 | +### Google SSO |
| 36 | + |
| 37 | +| Option | Description | |
| 38 | +|--------|-------------| |
| 39 | +| `GoogleServerClientId` | OAuth 2.0 **Web** client ID from Google Cloud Console. This is the client ID your backend uses to verify tokens. Required for native Android sign-in and the Google ID option in `GetPasswordCredential`. | |
| 40 | +| `GoogleIosClientId` | iOS-specific Google OAuth client ID (for browser flow on iOS). | |
| 41 | +| `GoogleIosRedirectUri` | Redirect URI for iOS browser-based Google auth. | |
| 42 | +| `GoogleAndroidRedirectUri` | Redirect URI for Android browser-based Google auth. | |
| 43 | +| `GoogleAndroidCallbackScheme` | Custom URL scheme for Android browser callback. | |
| 44 | + |
| 45 | +### Apple SSO |
| 46 | + |
| 47 | +| Option | Description | |
| 48 | +|--------|-------------| |
| 49 | +| `AppleServiceId` | Service ID from the Apple Developer portal. | |
| 50 | +| `AppleRedirectUri` | Redirect URI registered with Apple. | |
| 51 | +| `AppleAndroidCallbackScheme` | Callback scheme for Apple auth on Android. | |
| 52 | +| `AppleIosCallbackScheme` | Callback scheme for Apple auth on iOS. | |
| 53 | + |
| 54 | +### Auth method defaults |
| 55 | + |
| 56 | +| Provider | Android | iOS | |
| 57 | +|----------|---------|-----| |
| 58 | +| Google | Native | Browser | |
| 59 | +| Apple | Browser | Native | |
| 60 | + |
| 61 | +Override per-platform via `GoogleOnAndroid`, `AppleOnAndroid`, `GoogleOnIos`, `AppleOnIos`. Accepted values: `Native`, `Browser`, `Disabled`. |
| 62 | + |
| 63 | +## Password credentials — no SSO setup needed |
| 64 | + |
| 65 | +Saving and retrieving password credentials works without any SSO configuration. You can test `CreatePasswordCredential`, `GetPasswordCredential`, and `ClearCredentialState` immediately. |
| 66 | + |
| 67 | +## Running |
| 68 | + |
| 69 | +```bash |
| 70 | +# Android |
| 71 | +dotnet build -f net10.0-android |
| 72 | + |
| 73 | +# iOS |
| 74 | +dotnet build -f net10.0-ios |
| 75 | +``` |
| 76 | + |
| 77 | +## Android-specific notes |
| 78 | + |
| 79 | +- **⚠️ The `<ApplicationId>` in your `.csproj` must exactly match the package name registered in the Google Cloud Console for your OAuth client.** If they don't match, credential requests will silently fail or return empty results with no clear error message. The demo app uses `com.kebechet.demoapp` — make sure the same package name is configured in your Google Cloud project. |
| 80 | +- Requires `INTERNET` and `ACCESS_NETWORK_STATE` permissions (already in manifest). |
| 81 | +- For passkeys: set up an `assetlinks.json` on your domain and configure Digital Asset Links. |
| 82 | + |
| 83 | +## iOS-specific notes |
| 84 | + |
| 85 | +- Minimum deployment target: iOS 16.0 (required for ASAuthorization passkey APIs). |
| 86 | +- For Apple Sign In: enable the **Sign In with Apple** capability in the Apple Developer portal. |
| 87 | +- For passkeys: configure **Associated Domains** in your entitlements. |
0 commit comments