DioRed.Dais.Client 1.0.0-preview.4

Suggested Alternatives

DioRed.Aith.Client

Additional Details

DAIS has been completely renamed to Aith

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

DioRed.Dais.Client

DioRed.Dais.Client provides a strongly-typed, high-level DAIS client_credentials OAuth2 client for server-to-server communication.

It handles:

  • Fetching access tokens using client_id + client_secret
  • Token caching and automatic refresh
  • Attaching Authorization: Bearer headers to outgoing requests
  • Seamless HttpClient integration via IHttpClientFactory

🚀 Installation

dotnet add package DioRed.Dais.Client

✨ Quick Start

Register a DAIS-backed HttpClient:

builder.Services.AddDaisClient("my-api", o =>
{
    o.Authority    = "https://auth.example.com";
    o.ClientId     = "service-a";
    o.ClientSecret = builder.Configuration["Dais:ServiceA:Secret"];
    o.Scopes       = new[] { "my-api.read" };
});

builder.Services.AddHttpClient("my-api", client =>
{
    client.BaseAddress = new Uri("https://api.example.com");
});

Use it in services:

public class ApiService
{
    private readonly HttpClient _client;

    public ApiService(IHttpClientFactory factory)
    {
        _client = factory.CreateClient("my-api");
    }

    public async Task<string> GetDataAsync()
    {
        var response = await _client.GetStringAsync("/v1/data");
        return response;
    }
}

All requests automatically receive:

Authorization: Bearer {access_token}

🔐 How It Works

The library implements:

  1. DaisTokenClient

Retrieves and caches client_credentials tokens from:

POST {Authority}/oauth/token
grant_type=client_credentials
client_id=...
client_secret=...
scope=...
  1. DaisClientCredentialsHandler

A delegating handler that:

  • obtains a fresh token when needed,
  • attaches it to each outbound request.
  1. AddDaisClient(...) extension

Registers all required components with proper DI lifetimes.


⚙️ Advanced Usage

Custom scopes:

o.Scopes = new[] { "payments.write", "orders.read" };

Custom token endpoint:

o.TokenEndpoint = "https://auth.example.com/custom-token";

Multiple DAIS-backed HttpClients:

builder.Services.AddDaisClient("service-a", ...);
builder.Services.AddDaisClient("service-b", ...);

📚 Summary

Use DioRed.Dais.Client for any app-to-api or microservice-to-microservice authentication:

  • backend jobs
  • background services
  • microservice communication
  • internal admin tools
  • API gateways

For interactive login in web apps (Authorization Code + PKCE), use:

👉 DioRed.Dais.AspNetCore

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 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 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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.