Xylocopadream.Otp.Client 0.1.0

Prefix Reserved
dotnet add package Xylocopadream.Otp.Client --version 0.1.0
                    
NuGet\Install-Package Xylocopadream.Otp.Client -Version 0.1.0
                    
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="Xylocopadream.Otp.Client" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xylocopadream.Otp.Client" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Xylocopadream.Otp.Client" />
                    
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 Xylocopadream.Otp.Client --version 0.1.0
                    
#r "nuget: Xylocopadream.Otp.Client, 0.1.0"
                    
#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 Xylocopadream.Otp.Client@0.1.0
                    
#: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=Xylocopadream.Otp.Client&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Xylocopadream.Otp.Client&version=0.1.0
                    
Install as a Cake Tool

Xylocopadream.Otp.Client

Client for the Xylocopadream OTP server: passwordless login by e-mail code, secure token storage and automatic JWT refresh.

Usage

The client stores tokens through IEasySecureStorage, so register a platform implementation first (see Xylocopadream.EasySecureStorage.*).

builder.Services.AddEasySecureStorageMaui();
// audience: the service (API) the tokens are for, listed in the OTP server "JwtSettings:Audiences"
builder.Services.AddOtpModules(new Uri("https://otp.example.com/"), audience: "my-api");
public sealed class LoginViewModel(IAuthFacade auth)
{
    public Task<Resu<RequestAccessResult>> SendCodeAsync(string email)
        => auth.RequestAccessAsync(email);       // 1. the server e-mails a code

    public Task<Resu> LoginAsync(string email, string code)
        => auth.LoginAsync(email, code);         // 2. tokens are stored securely

    public Task<Resu<RestoreSessionResult>> RestoreAsync()
        => auth.RestoreSessionAsync();           // on startup, uses the refresh token
}

The session is exposed read-only and bindable through IAuthenticationState. When the refresh token is rejected (expired or revoked), the session is cleared and SessionExpired is raised:

app.Services.GetRequiredService<IAuthenticationState>().SessionExpired += (_, _) =>
    MainThread.BeginInvokeOnMainThread(() => navigator.NavigateTo<LoginPageIdentifier>());

To call your own APIs with the access token (refreshed automatically on expiry):

services.AddAuthenticatedHttpClient<MyApiClient>(new Uri("https://api.example.com/"));

License

GPL-3.0-or-later

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 42 10/7/2026