Class AuthorizationRequirement

Namespace
Cratis.Arc.Authorization
Assembly
Cratis.Arc.Core.dll

Represents one authorization requirement declared on a type or method: the caller must be authenticated and, when roles are given, hold at least one of them.

public record AuthorizationRequirement : IEquatable<AuthorizationRequirement>
Inheritance
AuthorizationRequirement
Implements
Inherited Members
Extension Methods

Remarks

Every requirement declared on a member must be satisfied, so two stacked authorization attributes require both, which matches how ASP.NET Core combines its own [Authorize] attributes.

Constructors

AuthorizationRequirement(AuthorizationRequirement)

protected AuthorizationRequirement(AuthorizationRequirement original)

Parameters

original AuthorizationRequirement

AuthorizationRequirement(IReadOnlyList<string>)

Represents one authorization requirement declared on a type or method: the caller must be authenticated and, when roles are given, hold at least one of them.

public AuthorizationRequirement(IReadOnlyList<string> AnyOfRoles)

Parameters

AnyOfRoles IReadOnlyList<string>

The roles the caller must hold at least one of, or empty when authentication alone suffices.

Remarks

Every requirement declared on a member must be satisfied, so two stacked authorization attributes require both, which matches how ASP.NET Core combines its own [Authorize] attributes.

Properties

AnyOfRoles

The roles the caller must hold at least one of, or empty when authentication alone suffices.

public IReadOnlyList<string> AnyOfRoles { get; init; }

Property Value

IReadOnlyList<string>

AuthenticationSchemes

Gets the explicitly requested authentication schemes.

public IReadOnlyList<string> AuthenticationSchemes { get; init; }

Property Value

IReadOnlyList<string>

EqualityContract

protected virtual Type EqualityContract { get; }

Property Value

Type

Policy

Gets the named policy, if any.

public string? Policy { get; init; }

Property Value

string

Methods

Deconstruct(out IReadOnlyList<string>)

public void Deconstruct(out IReadOnlyList<string> AnyOfRoles)

Parameters

AnyOfRoles IReadOnlyList<string>

Equals(AuthorizationRequirement?)

public virtual bool Equals(AuthorizationRequirement? other)

Parameters

other AuthorizationRequirement

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

FromAttribute(string?, string?, string?)

Creates a requirement from the settings of an authorization attribute.

public static AuthorizationRequirement FromAttribute(string? roles, string? policy, string? schemes)

Parameters

roles string

Comma-separated roles.

policy string

The named policy.

schemes string

Comma-separated authentication schemes.

Returns

AuthorizationRequirement

The complete requirement.

Exceptions

InvalidAuthorizationConfiguration

A policy name is whitespace or a scheme name in the list is empty.

FromRoles(string?)

Creates a requirement from a comma-separated roles value as carried by an authorization attribute.

public static AuthorizationRequirement FromRoles(string? roles)

Parameters

roles string

The comma-separated roles, or null or empty when authentication alone suffices.

Returns

AuthorizationRequirement

The AuthorizationRequirement.

GetHashCode()

public override int GetHashCode()

Returns

int

PrintMembers(StringBuilder)

protected virtual bool PrintMembers(StringBuilder builder)

Parameters

builder StringBuilder

Returns

bool

ToString()

public override string ToString()

Returns

string

Operators

operator ==(AuthorizationRequirement?, AuthorizationRequirement?)

public static bool operator ==(AuthorizationRequirement? left, AuthorizationRequirement? right)

Parameters

left AuthorizationRequirement
right AuthorizationRequirement

Returns

bool

operator !=(AuthorizationRequirement?, AuthorizationRequirement?)

public static bool operator !=(AuthorizationRequirement? left, AuthorizationRequirement? right)

Parameters

left AuthorizationRequirement
right AuthorizationRequirement

Returns

bool