Soenneker.Blazor.Utils.Session 4.0.2707

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Blazor.Utils.Session --version 4.0.2707
                    
NuGet\Install-Package Soenneker.Blazor.Utils.Session -Version 4.0.2707
                    
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="Soenneker.Blazor.Utils.Session" Version="4.0.2707" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.Utils.Session" Version="4.0.2707" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.Utils.Session" />
                    
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 Soenneker.Blazor.Utils.Session --version 4.0.2707
                    
#r "nuget: Soenneker.Blazor.Utils.Session, 4.0.2707"
                    
#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 Soenneker.Blazor.Utils.Session@4.0.2707
                    
#: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=Soenneker.Blazor.Utils.Session&version=4.0.2707
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.Utils.Session&version=4.0.2707
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Blazor.Utils.Session

Caches Blazor WebAssembly access tokens, refreshes tokens near expiration, and optionally redirects when session activity through the utility stops.

Install

dotnet add package Soenneker.Blazor.Utils.Session

Register the scoped service in Program.cs after configuring Blazor WebAssembly authentication:

using Soenneker.Blazor.Utils.Session.Registrars;

builder.Services.AddSessionUtilAsScoped();

Inject ISessionUtil where an access token is needed:

@using Soenneker.Blazor.Utils.Session.Abstract
@inject ISessionUtil Session
string accessToken = await Session.GetAccessToken(cancellationToken);

The utility uses the registered IAccessTokenProvider. It returns a cached token while that token has at least one minute remaining; otherwise it coalesces concurrent callers into one provider request. A provider request that does not finish within 30 seconds clears local session state and redirects to the session-expired route.

Configuration

Session:Uri controls the app-local route used for expiration and token-acquisition failures. It defaults to errors/sessionexpired.

An idle timeout is optional. Session:IdleTimeoutMinutes is preferred; Session:TimeoutMinutes is accepted as a fallback.

{
  "Session": {
    "Uri": "account/session-expired",
    "IdleTimeoutMinutes": 30
  }
}

Idle activity means calls to GetAccessToken or UpdateWithAccessToken; this package does not listen for mouse, keyboard, navigation, or network activity. Omit the timeout setting, set it to 0, or use a negative value to disable idle expiration.

Update expiration explicitly

GetAccessToken records the provider token's expiration automatically. If another authentication path obtains or renews a token, supply its UTC expiration:

await Session.UpdateWithAccessToken(jwtExpiration, cancellationToken);

When the timestamp is reached, the cached token is cleared. The next GetAccessToken call asks the provider for a token again.

Clear session state

Clear the cached token and cancel expiration timers without navigating:

await Session.ClearState();

Or clear state and navigate to the configured expiration route:

await Session.ClearStateAndRedirect(error: false, cancellationToken);

The error argument controls whether the event is logged as an error or normal expiration. Redirects are suppressed after the first one in a session state cycle. Updating the access-token expiration starts a new cycle.

Operational behavior

  • Clearing or disposing the session invalidates token requests already in flight; stale results cannot restore cleared state.
  • Cancelling one caller stops that caller from waiting. The underlying IAccessTokenProvider request may continue because its API does not accept a cancellation token.
  • Token-provider failures clear local state, redirect to the expiration route, and are rethrown to the caller.
  • The service is intended to be scoped. Dependency injection disposes it automatically; manually created instances must be disposed.
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 (1)

Showing the top 1 NuGet packages that depend on Soenneker.Blazor.Utils.Session:

Package Downloads
Soenneker.Blazor.ApiClient

A lightweight and efficient API client wrapper for Blazor applications, simplifying HTTP communication with support for asynchronous calls, cancellation tokens, and JSON serialization.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.2718 0 8/31/2026
4.0.2717 0 8/31/2026
4.0.2715 0 8/31/2026
4.0.2714 0 8/30/2026
4.0.2712 33 8/30/2026
4.0.2710 33 8/30/2026
4.0.2707 67 8/30/2026
4.0.2705 37 8/30/2026
4.0.2704 93 8/30/2026
4.0.2702 39 8/30/2026
4.0.2698 36 8/29/2026
4.0.2697 42 8/29/2026
4.0.2696 42 8/29/2026
4.0.2695 31 8/29/2026
4.0.2694 343 8/26/2026
4.0.2693 152 8/26/2026
4.0.2692 158 8/25/2026
4.0.2691 355 8/21/2026
4.0.2689 105 8/21/2026
4.0.2688 507 8/18/2026
Loading failed

Update dependency Soenneker.Asyncs.Locks to 4.0.71 (#3524)