Thima.MauiAuth.Core
1.0.2
dotnet add package Thima.MauiAuth.Core --version 1.0.2
NuGet\Install-Package Thima.MauiAuth.Core -Version 1.0.2
<PackageReference Include="Thima.MauiAuth.Core" Version="1.0.2" />
<PackageVersion Include="Thima.MauiAuth.Core" Version="1.0.2" />
<PackageReference Include="Thima.MauiAuth.Core" />
paket add Thima.MauiAuth.Core --version 1.0.2
#r "nuget: Thima.MauiAuth.Core, 1.0.2"
#:package Thima.MauiAuth.Core@1.0.2
#addin nuget:?package=Thima.MauiAuth.Core&version=1.0.2
#tool nuget:?package=Thima.MauiAuth.Core&version=1.0.2
MauiAuth
MauiAuth is a lightweight authentication-state framework for .NET MAUI inspired by Blazor's AuthenticationStateProvider.
Architecture
The recommended NuGet package is MauiAuth, which includes everything in one assembly:
- platform-neutral state provider, events, token store contracts, options, and authorization helpers
- JWT parsing and
ClaimsPrincipalcreation - token store implementations and secure-storage adapter contracts
DelegatingHandlerfor bearer token injection- dependency injection setup for app developers
The repository also keeps the smaller projects under src/ for development, but app developers should install the single MauiAuth package to avoid missing package references.
MauiAuth.Core targets net8.0 and does not reference MAUI.
Basic Usage
Install the dependency injection package:
dotnet add package MauiAuth
using MauiAuth.Core.Interfaces;
using MauiAuth.Extensions;
builder.Services.AddMauiAuth();
public sealed class LoginViewModel
{
private readonly IAuthenticationStateProvider _auth;
public LoginViewModel(IAuthenticationStateProvider auth)
{
_auth = auth;
_auth.AuthenticationStateChanged += (_, args) =>
{
var isAuthenticated = args.CurrentState.IsAuthenticated;
};
}
public Task SignInAsync(string jwt) => _auth.SignInAsync(jwt);
public Task SignOutAsync() => _auth.SignOutAsync();
}
if (auth.IsAuthenticated)
{
var user = auth.User;
}
MAUI SecureStorage Adapter
Bind MauiAuth.Storage to MAUI SecureStorage from your app project:
using MauiAuth.Extensions;
using MauiAuth.Storage.Services;
using Microsoft.Maui.Storage;
builder.Services
.AddMauiAuth()
.AddMauiAuthSecureStorage(_ => new DelegateSecureStorage(
SecureStorage.Default.GetAsync,
SecureStorage.Default.SetAsync,
SecureStorage.Default.Remove));
HttpClient Integration
using MauiAuth.Http.Handlers;
builder.Services.AddHttpClient("api", client =>
{
client.BaseAddress = new Uri("https://api.example.com");
})
.AddHttpMessageHandler<BearerTokenHandler>();
Session Restoration
Call session restore when the app starts:
var auth = services.GetRequiredService<IAuthenticationStateProvider>();
await auth.RestoreSessionAsync();
Sample App
See samples/MauiAuth.Sample for a runnable MAUI app that demonstrates:
- dependency injection setup
- MAUI
SecureStoragetoken persistence - session restoration
- sign in with a demo JWT
- sign out
AuthenticationStateChangedUI updates- claims and role display
Build the Windows target:
dotnet build samples/MauiAuth.Sample/MauiAuth.Sample.csproj -f net9.0-windows10.0.19041.0
Packaging
The all-in-one src/MauiAuth/MauiAuth.csproj project is the recommended package to publish. Before publishing, add icon/readme metadata and sign packages if your organization requires it.
dotnet pack src/MauiAuth/MauiAuth.csproj -c Release
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.