Skip to main content
Table of Contents

Interface IAuthorizationProvider

Namespace
Stratara.Abstractions.Authorization
Assembly
Stratara.Abstractions.dll

Provides role-membership checks for the authorizing mediator + command-outbox-dispatcher decorators. Implementations typically read from HttpContext.User, a JWT claim set, or a tenant-scoped identity service.

public interface IAuthorizationProvider
Extension Methods

Examples

Minimal ASP.NET Core implementation that reads from the current HttpContext.User:

public sealed class HttpContextAuthorizationProvider(IHttpContextAccessor accessor) : IAuthorizationProvider
{
    public Task<bool> IsInRoleAsync(string role, CancellationToken cancellationToken = default) =>
        Task.FromResult(accessor.HttpContext?.User?.IsInRole(role) ?? false);
}

builder.Services
    .AddHttpContextAccessor()
    .AddAuthorizingMediator<HttpContextAuthorizationProvider>();

Methods

IsInRoleAsync(string, CancellationToken)

Check whether the current caller holds role.

Task<bool> IsInRoleAsync(string role, CancellationToken cancellationToken = default)

Parameters

role string

The role name to check.

cancellationToken CancellationToken

Propagated by the caller.

Returns

Task<bool>

true if the caller is in the role; false otherwise.