Sondor.Authorization
1.0.0
See the version list below for details.
dotnet add package Sondor.Authorization --version 1.0.0
NuGet\Install-Package Sondor.Authorization -Version 1.0.0
<PackageReference Include="Sondor.Authorization" Version="1.0.0" />
<PackageVersion Include="Sondor.Authorization" Version="1.0.0" />
<PackageReference Include="Sondor.Authorization" />
paket add Sondor.Authorization --version 1.0.0
#r "nuget: Sondor.Authorization, 1.0.0"
#:package Sondor.Authorization@1.0.0
#addin nuget:?package=Sondor.Authorization&version=1.0.0
#tool nuget:?package=Sondor.Authorization&version=1.0.0
Sondor Authorization
The Sondor Authorization package provides a simplified way to set up .NET Core authorization and authentication using Microsoft Identity Web and JWT Bearer tokens. It is designed for easy integration with ASP.NET Core applications, supporting multi-tenant scenarios and secure API access.
Features
- Plug-and-play JWT Bearer authentication for ASP.NET Core.
- Integration with Microsoft Identity Web.
- Centralized configuration via
SondorAuthorizationOptions. - Customizable error handling and translation support.
- Validation for required authorization options.
Installation
Install via NuGet Package Manager:
Install-Package Sondor.Authorization
Or via .NET CLI:
dotnet add package Sondor.Authorization
Configuration
Add the following section to your appsettings.json (or any configuration source):
"SondorAuthorizationOptions": {
"TenantId": "<your-tenant-id>",
"ClientId": "<your-client-id>",
"ClientSecret": "<your-client-secret>",
"Instance": "https://login.microsoftonline.com/"
}
Usage
1. Register Authorization in Startup
In your Program.cs or Startup.cs, register Sondor Authorization:
using Sondor.Authorization;
var builder = WebApplication.CreateBuilder(args);
// Add Sondor Authorization
builder.Services.AddSondorAuthorization();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
You can specify a custom configuration section name if needed:
builder.Services.AddSondorAuthorization("Custom:Authorization");
2. Protect Endpoints
Use standard ASP.NET Core [Authorize] attributes to protect your controllers or actions:
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("[controller]")]
public class SecureController : ControllerBase
{
[Authorize]
[HttpGet]
public IActionResult GetSecret() {
return Ok("This is a protected resource.");
}
}
SondorAuthorizationOptions
The following options must be configured:
| Property | Description | Example Value |
|---|---|---|
| TenantId | Azure AD Tenant ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| ClientId | Azure AD Application Client ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| ClientSecret | Azure AD Application Secret | your-client-secret |
| Instance | Authority Instance URL | https://login.microsoftonline.com/ |
Validation is performed to ensure all fields are present and correctly formatted.
Error Handling
Custom exceptions are thrown for authentication and authorization failures:
UnauthorisedExceptionfor failed authentication.ForbiddenExceptionfor forbidden access.
Translations for error messages are supported via ISondorTranslationManager.
Testing
For unit/integration testing, use the provided helper:
builder.Services.AddTestSondorAuthorizationOptions();
This registers mock options and configuration for test scenarios.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please submit issues or pull requests via the repository.
Support
For questions or support, contact Sondor Dev or open an issue in the repository.
Example: Minimal API Setup
var builder = WebApplication.CreateBuilder(args); builder.Services.AddSondorAuthorization();
var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization();
app.MapGet("/secure", [Authorize] () => "Protected data");
app.Run();
| 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
- FluentValidation (>= 11.11.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.19)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Identity.Web (>= 3.13.1)
- Sondor.Translations (>= 1.0.8)
-
net9.0
- FluentValidation (>= 11.11.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.8)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Identity.Web (>= 3.13.1)
- Sondor.Translations (>= 1.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
The initial release.