OpenIdAuthClient 1.0.0

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

OpenIdAuthClient

A .NET 8 client library for integrating with the OpenIdAuthServer OAuth 2.0 / OpenID Connect authorization server.

Features

  • Authorization Code + PKCE flow - build authorization URLs, exchange codes for tokens, and refresh tokens securely.
  • Cookie authentication - ready-made integration with Microsoft.AspNetCore.Authentication.Cookies.
  • Scope-based authorization - includes [RequireScope] attribute, ScopePolicyProvider, and ScopeAuthorizationHandler for declarative scope checks.
  • User info endpoint - fetch authenticated user claims from the authorization server.
  • Strongly-typed configuration - bind settings from appsettings.json via AuthServerOptions.

Installation

dotnet add package OpenIdAuthClient

Quick Start

1. Configure appsettings.json

{
  "AuthServer": {
    "Authority": "https://your-auth-server.example.com",
    "ClientId": "my-client-id",
    "ClientSecret": "my-client-secret",
    "RedirectUri": "https://localhost:5001/auth/callback",
    "PostLogoutRedirectUri": "https://localhost:5001/",
    "Scopes": "openid profile email roles offline_access"
  }
}

2. Register services in Program.cs

using OpenIdAuthClient;

var builder = WebApplication.CreateBuilder(args);

// Bind options
builder.Services.Configure<AuthServerOptions>(
    builder.Configuration.GetSection(AuthServerOptions.SectionName));

// Register the typed HTTP client
builder.Services.AddHttpClient<AuthServerClient>();

// Add cookie authentication
builder.Services.AddAuthentication("Cookies")
    .AddCookie("Cookies");

// Add authorization
builder.Services.AddAuthorization();

var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.Run();

3. Use the client

public class AuthController : Controller
{
    private readonly AuthServerClient _client;

    public AuthController(AuthServerClient client) => _client = client;

    public IActionResult Login()
    {
        var authUrl = _client.BuildAuthorizationUrl();
        // Store authUrl.CodeVerifier and authUrl.State in the session
        return Redirect(authUrl.Url);
    }
}

4. Protect endpoints with scopes

[RequireScope("admin")]
public IActionResult AdminDashboard() => View();

Configuration Reference

Property Description Default
Authority Base URL of the authorization server (required)
ClientId OAuth 2.0 client identifier (required)
ClientSecret OAuth 2.0 client secret (required)
RedirectUri Redirect URI after login (required)
PostLogoutRedirectUri Redirect URI after logout (required)
Scopes Space-separated scopes to request openid profile email roles offline_access

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  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
1.0.0 266 3/24/2026

See CHANGELOG.md for release notes.