MonixOne.Security.Authentication 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MonixOne.Security.Authentication --version 1.0.1
                    
NuGet\Install-Package MonixOne.Security.Authentication -Version 1.0.1
                    
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="MonixOne.Security.Authentication" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MonixOne.Security.Authentication" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MonixOne.Security.Authentication" />
                    
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 MonixOne.Security.Authentication --version 1.0.1
                    
#r "nuget: MonixOne.Security.Authentication, 1.0.1"
                    
#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 MonixOne.Security.Authentication@1.0.1
                    
#: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=MonixOne.Security.Authentication&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MonixOne.Security.Authentication&version=1.0.1
                    
Install as a Cake Tool

MonixOne.Security.Authentication

Reusable JWT Bearer authentication и OAuth scope authorization для ASP.NET Core Resource Servers на .NET 10.

Библиотека проверяет:

  • подпись JWT по discovery/JWKS;
  • точный issuer;
  • точный audience;
  • обязательный exp и временные границы nbf/exp;
  • JOSE type at+jwt;
  • требуемый OAuth scope.

Она не выпускает tokens, не получает client credentials tokens и не заменяет domain authorization конечного сервиса.

Подключение

dotnet add package MonixOne.Security.Authentication

Добавьте настройки Resource Server:

{
  "Identity": {
    "Authority": "https://identity.example.com",
    "Audience": "beetroute-api",
    "RequireHttpsMetadata": true,
    "ClockSkewSeconds": 30
  }
}

ClockSkewSeconds задаётся в секундах и должен находиться в диапазоне 0..300. Отключение RequireHttpsMetadata разрешено только в окружении Local.

Зарегистрируйте authentication и необходимые сервису scope policies:

using MonixOne.Security.Authentication;

builder.Services.AddPlatformAuthentication(
    builder.Configuration,
    builder.Environment);

builder.Services.AddAuthorization(options =>
{
    options.AddScopePolicy("location.read");
    options.AddScopePolicy("location.write");
});

Названия scopes должны приходить из contracts конечной системы, а не из этой библиотеки.

Добавьте middleware в правильном порядке:

app.UseAuthentication();
app.UseAuthorization();

Защитите endpoint точным scope:

app.MapGet("/api/v1/locations", Handle)
    .RequireAuthorization(
        OAuthAuthorizationPolicies.ForScope("location.read"));

Для FastEndpoints используйте то же имя policy:

Policies(OAuthAuthorizationPolicies.ForScope("location.read"));

Health endpoints должны явно оставаться анонимными. Проверки владения ресурсом, ролей и других доменных правил выполняются после JWT/scope validation внутри конечного сервиса.

Публикация

Версия пакета задаётся свойством Version в MonixOne.Security.Authentication.csproj.

Workflow .github/workflows/publish.yml запускается только после merge pull request в main, повторно выполняет restore/build/test/pack и получает временный NuGet API key через Trusted Publishing. Постоянный NuGet API key в GitHub secrets не используется.

Для Trusted Publishing должны совпадать:

GitHub owner: Shulyakovskiy
Repository: MonixOne.Security.Authentication
Workflow: publish.yml
Environment: production

В GitHub Environment production требуется secret NUGET_USER с именем владельца NuGet.org. При повторной публикации существующей версии --skip-duplicate не создаёт новый пакет; перед релизом увеличьте Version.

Product Compatible and additional computed target framework versions.
.NET 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.

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.1.0 183 9/16/2026
1.0.1 143 9/14/2026
1.0.0 73 9/14/2026