SitecoreAPIAuthorization 0.9.2

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

Sitecore API Authorization

GitHub Workflow Status License .NET NuGet

A high-performance, thread-safe .NET library for managing Sitecore Cloud authentication tokens with automatic caching, cleanup, and comprehensive integration testing.

Quick Start

// 1. Install the package
dotnet add package SitecoreAPIAuthorization

// 2. Register services
services.AddLogging(b => b.SetMinimumLevel(LogLevel.Debug).AddConsole());
services.AddSitecoreAuthentication();

// 3. Use in your code
public class MyService
{
    private readonly ISitecoreTokenService _tokenService;
    
    public MyService(ISitecoreTokenService tokenService)
    {
        _tokenService = tokenService;
    }
    
    public async Task<SitecoreAuthToken> GetTokenAsync()
    {
        var credentials = new SitecoreAuthClientCredentials("client-id", "client-secret");
        return await _tokenService.GetSitecoreAuthToken(credentials);
    }
}

Key Features

  • Thread-safe token caching with high-performance concurrent operations
  • Automatic token refresh and expiration handling
  • Configurable cache management with smart cleanup strategies
  • Environment-specific configuration for development, staging, and production
  • Dependency injection integration with multiple registration patterns
  • Logging via Microsoft.Extensions.Logging with detailed debug and information messages (service and cache)
  • Comprehensive testing framework with unit and integration tests
  • Docker integration testing with real Keycloak instances and fast mock server

Logging

The library emits detailed logs that help diagnose authentication and caching behavior.

Service logs:

  • Token cache hit for clientId {ClientId}.
  • Requesting new token for clientId {ClientId} from {AuthUrl}.
  • Auth request payload and response status.
  • Authentication request failed with status {StatusCode} for {AuthUrl}. Body: <captured>
  • Failed to parse authentication response for clientId {ClientId}. Raw: <captured>
  • Authentication response was empty or missing access_token for clientId {ClientId}. Raw: <captured>
  • Token acquired and cached until {Expiration} for clientId {ClientId}.

Cache logs:

  • Cache miss for clientId {ClientId}.
  • Cache hit for clientId {ClientId}.
  • Token cached for clientId {ClientId} until {Expiration}.
  • Evicted {Count} token(s) due to cache size limit.
  • Cleanup removed {Count} expired token(s).
  • Cache cleared, removed {Count} token(s).
  • Removed token for clientId {ClientId} from cache.

Enable console logging at Debug level in development to see these details.

Quick Commands

# Run mock and infrastructure integration tests
dotnet test Sitecore.API.Foundation.Authorization.IntegrationTests --filter "MockIntegrationTests OR InfrastructureTests"

# Run logging integration tests only
dotnet test Sitecore.API.Foundation.Authorization.IntegrationTests --filter "FullyQualifiedName~LoggingIntegrationTests"

# Run all tests
dotnet test

License

MIT License - see LICENSE file for details.

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 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 (1)

Showing the top 1 NuGet packages that depend on SitecoreAPIAuthorization:

Package Downloads
SitecoreAPIGraphQLClient

DI-friendly, thread-safe GraphQL client factory for Sitecore with token authentication and 401 retry support.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.2 78 8/15/2025
0.9.1 172 8/15/2025
0.9.0 150 8/12/2025

See CHANGELOG.md for release notes.