Abstractions

Dosaic.Plugins.Authorization.Abstractions provides shared authorization primitives for the Dosaic plugin ecosystem. It defines a model for role-based authorization policies (AuthPolicy) and a set of extension helpers (PolicyExtensions) that make it straightforward to register pre-built or custom policies with ASP.NET Core's authorization middleware.

Concrete authentication plugins (e.g. Dosaic.Plugins.Authorization.Keycloak) depend on this package to declare and wire up their policies in a uniform way.

Installation

dotnet add package Dosaic.Plugins.Authorization.Abstractions

Or add as a package reference to your .csproj:

<PackageReference Include="Dosaic.Plugins.Authorization.Abstractions" Version="" />

Types

AuthPolicy

Represents a named ASP.NET Core authorization policy that requires the authenticated user to hold one or more roles.

Property
Type
Description

Name

string

The policy name used when calling [Authorize(Policy = "...")].

Roles

IList<string>

The roles the user must possess for the policy to succeed.


PolicyExtensions

A static helper class that exposes two pre-built policies and two extension methods for AuthorizationOptions.

Pre-built policies

Field
Type
Description

AuthenticatedPolicy

AuthorizationPolicy

Requires the user to be authenticated (RequireAuthenticatedUser()).

AllowAllPolicy

AuthorizationPolicy

Allows every request regardless of authentication state (RequireAssertion(_ => true)).

Extension methods

Method
Description

AddDefaultPolicy(AuthorizationOptions, AuthorizationPolicy)

Sets the supplied policy as both the default policy and registers it under the name "DEFAULT".

AddAuthPolicies(AuthorizationOptions, IEnumerable<AuthPolicy>)

Iterates a collection of AuthPolicy objects and registers each one as a named role-based policy.

Usage

Registering the default "authenticated" policy

Registering a permissive (allow-all) policy — useful for development or disabled auth

Registering role-based policies from configuration

Apply the named policy on a controller or endpoint:

Driving policies from appsettings

When using the Keycloak plugin, AuthPolicy instances are typically loaded from configuration:

The Keycloak plugin reads the policies list as IList<AuthPolicy> and passes it to options.AddAuthPolicies(...) during ConfigureServices.

Last updated