SyntaxCircus.Maui.TokenStorage 0.1.1

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SyntaxCircus.Maui.TokenStorage" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyntaxCircus.Maui.TokenStorage" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="SyntaxCircus.Maui.TokenStorage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SyntaxCircus.Maui.TokenStorage --version 0.1.1
                    
#r "nuget: SyntaxCircus.Maui.TokenStorage, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SyntaxCircus.Maui.TokenStorage@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SyntaxCircus.Maui.TokenStorage&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=SyntaxCircus.Maui.TokenStorage&version=0.1.1
                    
Install as a Cake Tool

SyntaxCircus.Maui.TokenStorage

Build NuGet License: MIT

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
0.1.3 124 8/17/2026
0.1.2 113 8/16/2026
0.1.1 103 8/16/2026