Ling.Blazor.Authentication
0.0.4
dotnet add package Ling.Blazor.Authentication --version 0.0.4
NuGet\Install-Package Ling.Blazor.Authentication -Version 0.0.4
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="Ling.Blazor.Authentication" Version="0.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ling.Blazor.Authentication --version 0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ling.Blazor.Authentication, 0.0.4"
#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.
// Install Ling.Blazor.Authentication as a Cake Addin #addin nuget:?package=Ling.Blazor.Authentication&version=0.0.4 // Install Ling.Blazor.Authentication as a Cake Tool #tool nuget:?package=Ling.Blazor.Authentication&version=0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Introduction
Ling.Blazor.Authentication
is a library that provides JWT authentication for Blazor applications.
Installation
- Package Manager
You can install this library using either Package Manager or .NET CLI.
PM> Install-Package Ling.Blazor.Authentication
- .NET CLI
dotnet add package Ling.Blazor.Authentication
Usage
To use this library, you need to follow these steps:
- Implement your own
JwtAuthenticationService
class that inherits fromJwtAuthenticationServiceBase
class. For example:
public class JwtAuthenticationService : JwtAuthenticationServiceBase
{
public AuthenticationService(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
public Task LoginAsync(string username, string password, bool isPersistent = false, CancellationToken cancellationToken = default)
{
// Write your login logic here and get the tokenInfo object
// Remember to call 'SetTokenAsync' to save the tokenInfo
await SetTokenAsync(tokenInfo, cancellationToken);
}
}
- Register the services in
Program.cs
file. For example:
builder.Services.AddJwtAuthorization<JwtAuthenticationService>(); // You can configure 'JwtAuthOptions' here if needed
builder.Services.AddServerAPI(baseAddress); // Replace baseAddress with your actual API server address
The AddServerAPI
method will register an HttpClient
for you, which will automatically set the Authorization
header for your requests.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Blazored.LocalStorage (>= 4.3.0)
- Microsoft.AspNetCore.Components.Authorization (>= 6.0.16)
- Microsoft.Extensions.Http (>= 6.0.0)
-
net7.0
- Blazored.LocalStorage (>= 4.3.0)
- Microsoft.AspNetCore.Components.Authorization (>= 7.0.5)
- Microsoft.Extensions.Http (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.