Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace OpenHealthOS.Contracts.Authorization;

using OpenHealthOS.Contracts.Identity;

/// <summary>
/// Represents the information required to evaluate an authorization request.
/// </summary>
public sealed record AuthorizationContextDto
{
/// <summary>
/// Gets the authenticated identity associated with the request.
/// </summary>
public required IdentityContextDto Identity { get; init; }

/// <summary>
/// Gets the permission being requested.
/// </summary>
public required Permission Permission { get; init; }

/// <summary>
/// Gets the resource type against which authorization is evaluated.
/// </summary>
public required string ResourceType { get; init; }

/// <summary>
/// Gets the optional resource identifier.
/// </summary>
public string? ResourceId { get; init; }

/// <summary>
/// Gets the optional tenant identifier associated with the resource.
/// </summary>
public string? TenantId { get; init; }

/// <summary>
/// Gets the optional organization identifier associated with the resource.
/// </summary>
public string? OrganizationId { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace OpenHealthOS.Contracts.Authorization;

/// <summary>
/// Represents the outcome of an authorization evaluation.
/// </summary>
public enum AuthorizationDecision
{
/// <summary>
/// Access is allowed.
/// </summary>
Allow = 1,

/// <summary>
/// Access is denied.
/// </summary>
Deny = 2,
}
34 changes: 34 additions & 0 deletions src/BuildingBlocks/Contracts/Authorization/Permission.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace OpenHealthOS.Contracts.Authorization;

/// <summary>
/// Represents a named authorization permission.
/// </summary>
public sealed record Permission
{
/// <summary>
/// Initializes a new instance of the <see cref="Permission"/> class.
/// </summary>
/// <param name="value">The stable permission identifier.</param>
public Permission(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException(
"Permission value cannot be null or whitespace.",
nameof(value));
}

Value = value;
}

/// <summary>
/// Gets the stable permission identifier.
/// </summary>
public string Value { get; }

/// <summary>
/// Returns the permission identifier.
/// </summary>
/// <returns>The permission identifier string.</returns>
public override string ToString() => Value;
}
Loading