Mahta.Utilities.Auth.ApiAuthorization 10.0.0

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

Mahta.Utilities.Auth.ApiAuthorization

Shared API authorization contracts for services that ask Access for authorization decisions.

Current scope:

  • Runtime enforcement for services that ask Access for authorization decisions.
  • References Mahta.Utilities.Auth.ApiAuthorization.Abstractions for decision contracts, enums, targets, and IRequestAuthorization.
  • IAuthorizationSubjectAccessor for resolving the current authenticated caller as a human user or machine client.
  • HttpContextAuthorizationSubjectAccessor as the default ASP.NET Core subject accessor.
  • IAuthorizationActingAsAccessor for resolving the current UI-selected actor mode from request context.
  • HttpContextAuthorizationActingAsAccessor as the default header-based acting-mode accessor.
  • IAuthorizationDecisionRequestFactory for combining request metadata and current subject into an Access decision request.
  • IApiAuthorizationEnforcer for executing the end-to-end decision flow without MVC/filter coupling.
  • Global MVC authorization filter for actions whose request DTO has an IRequestAuthorizationRule<TRequest> or implements IRequestAuthorization.
  • AllowUnauthorizedAttribute for explicitly skipping Mahta API authorization on an action or controller.
  • IAuthorizationDecisionClient and ApiAuthorizationOptions for the future Access decision HTTP client boundary.
  • HttpAuthorizationDecisionClient for posting decision requests to Access with the package OAuth token.
  • Access decision HTTP client uses Steeltoe service discovery, so AccessServiceName may be a logical service name.
  • OAuth settings are grouped under ApiAuthorizationOptions.OAuth for the Access decision call.
  • OAuth uses Authority plus MetadataAddress; the token endpoint is discovered from the OpenID Connect metadata document.
  • OAuth IgnoreSSL affects only the discovery/token HTTP client and should be treated as a temporary local or internal transition setting.
  • Duende AccessTokenManagement owns client-credentials token acquisition, token caching, and bearer-token attachment.
  • AddMahtaApiAuthorization(...) for registering options, request-building services, authorization rules, and the global MVC filter.
  • Options are validated during registration/startup when authorization is enabled.

Endpoint enforcement is automatic for MVC actions that receive a request DTO with a registered authorization rule. The older IRequestAuthorization DTO style is still supported as a fallback.

Host configuration

Register the package from the host service. Prefer the config-section plus project base-name style:

builder.Services.AddMahtaApiAuthorization(
    builder.Configuration,
    "ApiAuthorization",
    "Access");

This scans runtime assemblies matching Access for IRequestAuthorizationRule<TRequest> implementations.

For tests or explicit setup, use the delegate overload:

builder.Services.AddMahtaApiAuthorization(
    options =>
    {
        options.Enabled = true;
        options.AccessServiceName = "Access";
        options.DecisionEndpoint = "/api/v2/Authorization/Decide";
    },
    "Access");

Example configuration:

{
  "ApiAuthorization": {
    "Enabled": true,
    "AccessServiceName": "Access",
    "DecisionEndpoint": "/api/v2/Authorization/Decide",
    "DecisionTimeoutSeconds": 10,
    "OAuth": {
      "Authority": "https://auth.mahtaengine.ir",
      "MetadataAddress": "https://auth:8443/.well-known/openid-configuration",
      "IgnoreSSL": true,
      "ClientId": "platform-internal",
      "ClientSecret": "...",
      "Scopes": [ "mahta_api" ]
    }
  }
}

Authority is the trusted token issuer. MetadataAddress is where the service can reach Auth discovery. The discovered token_endpoint is then used by Duende AccessTokenManagement to request and cache the package token.

Request rule usage

Keep request DTOs clean:

public class GetOrdersRequest : IQuery<PagedData<OrderDto>>
{
    public Guid TenantId { get; set; }
    public Guid CenterId { get; set; }
}

Put the authorization requirement in a small rule class:

public class GetOrdersAuthorizationRule
    : IRequestAuthorizationRule<GetOrdersRequest>
{
    public ValueTask<RequestAuthorizationRequirement> GetRequirementAsync(
        GetOrdersRequest request,
        CancellationToken cancellationToken = default)
        => ValueTask.FromResult(
            RequestAuthorizationRequirement.Require(
                AuthorizationTargets.Center(request.TenantId, request.CenterId),
                "orders.read"));
}

The global MVC filter protects the action automatically:

[HttpPost("orders/search")]
public Task<IActionResult> Search([FromBody] GetOrdersRequest request)
    => Query<GetOrdersRequest, PagedData<OrderDto>>(request);

The filter resolves IRequestAuthorizationRule<GetOrdersRequest>, builds an Access decision request from the current authenticated subject, and calls Access before the action body continues.

Request DTO fallback

API request DTOs declare authorization metadata by implementing IRequestAuthorization:

public class GetOrdersRequest : IRequestAuthorization
{
    public Guid TenantId { get; set; }
    public Guid CenterId { get; set; }

    public AuthorizationTarget AuthorizationTarget
        => AuthorizationTargets.Center(TenantId, CenterId);

    public IReadOnlyCollection<string> AuthorizationPermissions
        => [ "orders.read" ];
}

This style is still supported, but the rule style keeps DTOs cleaner:

[HttpPost("orders/search")]
public Task<IActionResult> Search([FromBody] GetOrdersRequest request)
    => Query<GetOrdersRequest, PagedData<OrderDto>>(request);

The filter builds an Access decision request from the current authenticated subject and the DTO metadata.

Use [AllowUnauthorized] to skip Mahta API authorization for a specific action or controller. This does not skip authentication or other ASP.NET authorization policies.

The UI/runtime supplies the human acting mode through a standard header, not through every request DTO:

X-Authorization-Acting-As: TenantMember

Valid values are TenantMember, PlatformMember, and PlatformSupport. Machine callers or requests without a UI mode can omit the header; the package sends Unspecified.

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
10.0.0 97 9/13/2026
9.10.1 142 6/22/2026
9.10.0 347 9/29/2025
9.0.1 187 9/28/2025