SyntaxCircus.Maui.TokenStorage
0.1.1
See the version list below for details.
dotnet add package SyntaxCircus.Maui.TokenStorage --version 0.1.1
NuGet\Install-Package SyntaxCircus.Maui.TokenStorage -Version 0.1.1
<PackageReference Include="SyntaxCircus.Maui.TokenStorage" Version="0.1.1" />
<PackageVersion Include="SyntaxCircus.Maui.TokenStorage" Version="0.1.1" />
<PackageReference Include="SyntaxCircus.Maui.TokenStorage" />
paket add SyntaxCircus.Maui.TokenStorage --version 0.1.1
#r "nuget: SyntaxCircus.Maui.TokenStorage, 0.1.1"
#:package SyntaxCircus.Maui.TokenStorage@0.1.1
#addin nuget:?package=SyntaxCircus.Maui.TokenStorage&version=0.1.1
#tool nuget:?package=SyntaxCircus.Maui.TokenStorage&version=0.1.1
SyntaxCircus.Maui.TokenStorage
Secure auth token storage for MAUI apps: an injectable wrapper over ISecureStorage, and a session layer that splits sensitive tokens (secure storage) from non-sensitive metadata (IPreferences) so expiry checks don't need a keystore round-trip on every read.
No support guaranteed. Published as-is and maintained on a best-effort basis. Issues and PRs are welcome, but there's no SLA — fork it or vendor what you need if that's not enough.
Targets
net10.0-android and net10.0-ios. Depends on Microsoft.Maui.Controls — as of current .NET MAUI there's no narrower package that exposes ISecureStorage/IPreferences on their own, so a storage-only library still pulls in the full Controls surface. If your app already references Microsoft.Maui.Controls (nearly all MAUI apps do), this adds nothing new.
Setup
// MauiProgram.cs
builder.Services.AddSecureTokenStorage();
Usage
await sessionTokenStore.StoreAsync(new SessionTokens(
AccessToken: response.AccessToken,
RefreshToken: response.RefreshToken,
ExpiresAt: response.ExpiresAt,
UserId: response.UserId,
Email: response.Email,
IsAnonymous: false));
if (sessionTokenStore.HasValidAccessToken()) // synchronous — reads Preferences, not the keystore
{
var accessToken = await sessionTokenStore.GetAccessTokenAsync();
}
await sessionTokenStore.ClearAsync(); // sign out
Why expiry lives in Preferences, not secure storage
HasValidAccessToken() is called far more often than the token is actually read — every outgoing API call, typically — and a keystore round-trip on each of those is unnecessary overhead for a non-sensitive value. Expiry is also stored as a string, not a raw Unix-seconds integer: iOS's NSUserDefaults (what IPreferences maps to under the hood) stores integers as double, which silently loses precision for large epoch values. Storing the string form and parsing it back avoids that class of bug entirely.
Testing
ISecureTokenStorage is the seam — substitute your own implementation (or a test double) instead of SecureTokenStorage to unit test code that depends on SessionTokenStore without touching the platform keystore.
Contributing
Issues and pull requests are welcome:
- Keep changes focused, with a clear description of the behavior change.
- Match the existing code style (see
.editorconfig). - Call out any breaking changes to the public API in your PR description.
License
MIT — see LICENSE.txt.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-android36.0 is compatible. net10.0-browser was computed. net10.0-ios was computed. net10.0-ios26.0 is compatible. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Maui.Controls (>= 10.0.70)
-
net10.0-android36.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Maui.Controls (>= 10.0.70)
-
net10.0-ios26.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Maui.Controls (>= 10.0.70)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SyntaxCircus.Maui.TokenStorage:
| Package | Downloads |
|---|---|
|
SyntaxCircus.Maui.Environments
Runtime environment switching for MAUI apps that ship one binary across multiple backends (e.g. UAT/Production): a persisted environment selector with TTL-based default reversion, a switch coordinator that serializes app-supplied teardown/rebuild logic, environment-namespacing decorators for IPreferences/ISecureTokenStorage, and best-effort app-distribution-channel detection (TestFlight/Play/sideload). |
GitHub repositories
This package is not used by any popular GitHub repositories.