SitecoreAPIAuthorization 0.9.2
dotnet add package SitecoreAPIAuthorization --version 0.9.2
NuGet\Install-Package SitecoreAPIAuthorization -Version 0.9.2
<PackageReference Include="SitecoreAPIAuthorization" Version="0.9.2" />
<PackageVersion Include="SitecoreAPIAuthorization" Version="0.9.2" />
<PackageReference Include="SitecoreAPIAuthorization" />
paket add SitecoreAPIAuthorization --version 0.9.2
#r "nuget: SitecoreAPIAuthorization, 0.9.2"
#:package SitecoreAPIAuthorization@0.9.2
#addin nuget:?package=SitecoreAPIAuthorization&version=0.9.2
#tool nuget:?package=SitecoreAPIAuthorization&version=0.9.2
Sitecore API Authorization
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 | Versions 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. |
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Http (>= 9.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Options (>= 9.0.8)
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Http (>= 9.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Options (>= 9.0.8)
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.
See CHANGELOG.md for release notes.