IdentityWebApp.Api 3.2.1

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

About

The IdentityWebApp.Api package provides a comprehensive set of tools for implementing authentication and authorization in .NET applications. It offers a clean and modern API for handling user credentials and managing access tokens.

How to Use

Using the Authentication Service class

The AuthenticationService class is used to authenticate a user. It encapsulates:

  • Correct creation and configuration of HttpClient;
  • Serialization/deserialization of requests and responses;
  • Proper error handling;
  • Communication with IdentityWebApp REST API endpoints.

Important: The AuthenticationService must be created via dependency injection or with a properly configured IHttpClientFactory.

Example for Regular Applications (Manual Setup)

using IdentityWebApp.Api.Helpers;
using IdentityWebApp.Api.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http;

// Configure authentication settings
var authSettings = new AuthenticationSettings
{
    ServerName = "localhost",
    Port = 7121,
    UseHttps = false
};

// Get base address
var baseAddress = ApiUrlHelper.GetBaseAddress(authSettings);

// Create service collection and HttpClientFactory
var services = new ServiceCollection();

services.AddHttpClient(ApiConstants.HttpClientName, client =>
{
    client.BaseAddress = baseAddress;
    client.Timeout = TimeSpan.FromSeconds(ApiConstants.DefaultHttpClientTimeoutSeconds);
});

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();

// Create AuthenticationService instance
var authService = new AuthenticationService(httpClientFactory);

// Perform login
try
{
    var token = await authService.LoginAsync(
        "user@example.com",
        "securepassword"
    );
    
    Console.WriteLine($"Token: {token.Value}");
    Console.WriteLine($"Expires: {token.Expires}");
}
catch (Exception ex)
{
    Console.WriteLine($"Authentication failed: {ex.Message}");
}

Using the ServiceCollectionExtensions Class

For web applications, use the ServiceCollectionExtensions class to register the authentication service with the DI container.

Example for Web Applications (ASP.NET Core)

var builder = WebApplication.CreateBuilder(args);

// Add authentication service with default Scoped lifetime
builder.Services.AddIdentityWebAppAuthentication(builder.Configuration);

// Or specify different service lifetime:

// Transient
builder.Services.AddIdentityWebAppAuthentication(
    builder.Configuration,
    ServiceLifetime.Transient
);

// Singleton
builder.Services.AddIdentityWebAppAuthentication(
    builder.Configuration,
    ServiceLifetime.Singleton
);

Important: Make sure to add the Authentication section to your appsettings.json:

{
  "Authentication": {
    "ServerName": "localhost",
    "Port": 7121,
    "UseHttps": false
  }
}

Main Types

The main types provided by this library are:

  • IdentityWebApp.Api.Services.IAuthenticationService
  • IdentityWebApp.Api.Services.AuthenticationService
  • IdentityWebApp.Api.Models.TokenModel
  • IdentityWebApp.Api.Models.UserModel
  • IdentityWebApp.Api.Settings.AuthenticationSettings
  • IdentityWebApp.Api.Extensions.ServiceCollectionExtensions
  • IdentityWebApp.Api.Helpers.ApiUrlHelper
  • IdentityWebApp.Api.Constants.ApiConstants
  • IdentityWebApp.Api.Constants.ErrorMessagesConstants

Feedback & Contributing

IdentityWebApp.Api is released as open source under the MIT license. Bug reports, feature requests, and contributions are welcome at the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
3.2.1 90 5/24/2026
3.2.0 96 5/16/2026
3.1.0 96 5/7/2026
3.0.0 85 5/6/2026
2.0.0 111 4/4/2026
1.0.4 114 3/28/2026
1.0.3 107 3/5/2026
1.0.2 112 3/1/2026
1.0.1 105 2/28/2026
1.0.0 120 2/7/2026