Path: redb-identity/src/redb.Identity.Core/Configuration/AdminScopeEntitlementOptions.cs
Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/src/redb.Identity.Core/Configuration/AdminScopeEntitlementOptions.cs
----
namespace redb.Identity.Core.Configuration;
///
/// Role-driven entitlement for administrative scopes.
///
/// OAuth checks a scope against the client: may this application ask for it? That answer says
/// nothing about the person signing in, so a console permitted to request identity:manage handed
/// the master management scope to every account that could log into it. This gate adds the missing half
/// for user-bound grants: an administrative scope survives only when the user's effective roles carry
/// it. The client_credentials grant is untouched — it has no user, and the application's
/// scp:{scope} permission remains its authoritative gate.
///
///
/// What counts as administrative is deliberately narrow and explicit: Identity's own management surface
/// (identity:*) and SCIM. An operator's own scopes are none of this gate's business unless they
/// are listed here. identity:account is exempt — it is the self-service scope every signed-in
/// user is meant to hold.
///
///
public sealed class AdminScopeEntitlementOptions
{
///
/// Master switch, on by default. Turning it off restores the pre-gate behaviour, where any account
/// that can sign in to a console permitted to request identity:manage holds it. Present so a
/// deployment that locks itself out can recover from configuration alone, without a rebuild.
///
public bool Enabled { get; set; } = true;
/// Scope-name prefixes that require an entitling role. Default: identity:.
public List GatedPrefixes { get; set; } = new() { "identity:" };
/// Individual scope names that require an entitling role. Default: scim.
public List GatedScopes { get; set; } = new() { "scim" };
///
/// Scopes never gated even when a prefix matches. Default: identity:account — self-service
/// over one's own profile, which every signed-in user is supposed to have.
///
public List Exempt { get; set; } = new() { "identity:account" };
/// True when may only be issued to a user whose roles carry it.
public bool IsGated(string scope)
{
if (string.IsNullOrEmpty(scope)) return false;
foreach (var exempt in Exempt)
{
if (string.Equals(scope, exempt, StringComparison.Ordinal)) return false;
}
foreach (var gated in GatedScopes)
{
if (string.Equals(scope, gated, StringComparison.Ordinal)) return true;
}
foreach (var prefix in GatedPrefixes)
{
if (!string.IsNullOrEmpty(prefix) && scope.StartsWith(prefix, StringComparison.Ordinal)) return true;
}
return false;
}
}