GrayMint.Authorization.RoleManagement.Abstractions 3.2.209

dotnet add package GrayMint.Authorization.RoleManagement.Abstractions --version 3.2.209
                    
NuGet\Install-Package GrayMint.Authorization.RoleManagement.Abstractions -Version 3.2.209
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GrayMint.Authorization.RoleManagement.Abstractions" Version="3.2.209" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GrayMint.Authorization.RoleManagement.Abstractions" Version="3.2.209" />
                    
Directory.Packages.props
<PackageReference Include="GrayMint.Authorization.RoleManagement.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GrayMint.Authorization.RoleManagement.Abstractions --version 3.2.209
                    
#r "nuget: GrayMint.Authorization.RoleManagement.Abstractions, 3.2.209"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GrayMint.Authorization.RoleManagement.Abstractions@3.2.209
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GrayMint.Authorization.RoleManagement.Abstractions&version=3.2.209
                    
Install as a Cake Addin
#tool nuget:?package=GrayMint.Authorization.RoleManagement.Abstractions&version=3.2.209
                    
Install as a Cake Tool

GrayMint.Authorization

Modular B2B Authorization Framework for .NET Applications

GrayMint.Authorization provides a flexible, multi-tenant-compatible B2B authorization framework for .NET apps. It enables role-based and resource-based access control, ideal for enterprise platforms, SaaS systems, and microservices.


๐Ÿ”ง Features

  • Role-based and resource-based authorization
  • Multi-tenant (B2B) ready
  • Modular service registration and layering
  • Microservice-compatible with extensible providers
  • EF Core-based persistence support
  • Built-in controllers and services for quick bootstrap

๐Ÿ“ฆ Installation

Install the packages from nuget.org:

dotnet add package GrayMint.Authorization

๐Ÿš€ Getting Started

1. Configure App Settings

  • Issuer: The issuer of the tokens.
  • Audience: The audience of the tokens.
  • Audiences: More audiences to accept but never to issue, such as the old one while a service moves its tokens to a new Audience.
  • Secret: The secret key for token generation.
  • Secrets: List of additional secret keys.
  • CacheTimeout: The cache timeout duration.
  • AllowUserSelfRegister: Boolean flag to allow or disallow user self-registration.
  • AllowUserApiKey: Boolean flag to allow or disallow user API keys.
  • AllowRefreshToken: Boolean flag to allow or disallow refresh tokens.
  • SignInRedirectUrl: The URL to redirect to after sign-in.
  • OpenIdProviders: List of OpenID providers with their respective configurations.
  • AllowSystemApiKey: Allows the anonymous system api-key endpoints, which take the signing secret. Unset, they work in Development only.

Every access token carries an authorization_code claim, checked on each request so that the token can be revoked; a token without one is refused. A token meant to outlive any revocation, such as a customer token, carries *.

A person added to a resource by email shows to its team by email only until their first request to that resource, so adding an email shows the team nothing of that person's profile. Bots, which the team's own admins create, show in full. Removing someone's last role deletes a bot, or an account an email add made that was never used, but never a person who has signed in.

Upgrading an existing SQL Server database: the role provider creates missing tables, not missing columns, so add ConfirmedTime before the new version starts. The members already on a team are confirmed once, with the column, so they keep showing in full:

IF COL_LENGTH('gmrole.UserRoles', 'ConfirmedTime') IS NULL
BEGIN
    ALTER TABLE [gmrole].[UserRoles] ADD [ConfirmedTime] datetime2(0) NULL
    EXEC('UPDATE [gmrole].[UserRoles] SET [ConfirmedTime] = SYSUTCDATETIME()')
END

Emails are looked up and stored lower-cased. On a database that compares text case-sensitively (PostgreSQL, SQLite), lower-case the emails already stored once, or an email stored in another case is not found and adding it again creates a second account.

2. Service Registration (from Sample Web API)

var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;

// Load options
var appOptions = builder.Configuration.GetSection("App").Get<AppOptions>();
services.Configure<AppOptions>(builder.Configuration.GetSection("App"));

// Register shared services and Swagger
services
    .AddGrayMintCommonServices();

// Register Authorization and Roles
builder.AddGrayMintCommonAuthorizationForApp(
    GmRole.GetAll(typeof(Roles)),
    options => options.UseSqlServer(builder.Configuration.GetConnectionString("AppDatabase")));

// Optional: Register Resource Provider
if (appOptions.UseResourceProvider)
    services.AddGrayMintResourceProvider(
        new ResourceProviderOptions(),
        options => options.UseSqlServer(builder.Configuration.GetConnectionString("AppDatabase")));

// Add EF Core & domain services
services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("AppDatabase")));
services.AddItemServices();

3. Middleware & Execution

var webApp = builder.Build();
webApp.UseGrayMintCommonServices();
await webApp.UseGrayMinCommonAuthorizationForApp();
await webApp.Services.UseGrayMintDatabaseCommand<AppDbContext>(args);

if (appOptions.UseResourceProvider)
    await webApp.Services.UseGrayMintResourceProvider();

await GrayMintApp.RunAsync(webApp, args);

๐Ÿงช Permission Check Example

    [HttpGet("itemId/by-role")]
    [Authorize("DefaultPolicy", Roles = ["SystemAdmin", "SystemReader"])
    public Task<Item> GetByRole(int appId, int itemId)
    {
        return itemService.Get(appId, itemId);
    }

    [HttpPost("by-permission")]
    [AuthorizeAppIdPermission(Permissions.AppWrite)]
    public Task<Item> CreateByPermission(int appId, ItemCreateRequest? createRequest = null)
    {
        return itemService.Create(appId, createRequest);
    }

๐Ÿงฉ Extending

Implement custom providers:

  • IRoleProvider
  • IUserProvider
  • IResourceProvider

These interfaces allow full control over how roles, users, and resources are managed.

An IAuthorizationProvider's answers for a token are cached by the token's claims, leaving out the ones every copy differs in (jti, iat, exp, nbf, and a refresh token's embedded access token), so they must not depend on those.


๐Ÿ”‘ An OpenID Connect identity provider's tokens

GrayMint.Authorization.OpenIdAuthentications is a package of its own, for a service whose people sign in at an OpenID Connect identity provider and that issues no tokens itself. It needs none of the authentication packages above; the roles and permissions work with it as they are.

services
    .AddAuthentication(OpenIdAuthenticationDefaults.AuthenticationScheme)
    .AddGrayMintOpenIdAuthentication(new OpenIdAuthenticationOptions {
        Providers = [
            new OpenIdProviderOptions {
                Name = "main",                       // never changes: users are tied under it
                Issuer = "https://id.example.com/",  // as the provider's tokens carry it
                Audience = "files.example.com",      // this service, as its access tokens name it
                ClientIds = ["files"]                // the applications whose people sign in here
            }
        ]
    });
services.AddGrayMintOpenIdAuthenticationDb(options => options.UseNpgsql(connectionString));
  • An access token is taken only as the provider's own, for this service: signed by a key the provider publishes, in the one way it signs, in its name, naming this service as its audience, not run out, and an access token by its own word (typ is at+jwt), which an ID token of the same provider is not. The provider's keys are read from its address, and again when a token names one that isn't known yet.
  • A name is read to its last letter. An audience or an application whose name is this one's with a slash more is another one.
  • A caller is a user only by a binding: the provider's own id of the account (sub), tied to a local user. An account that is tied to nobody is refused, whatever its token says; an address in a token ties nobody. The id may be as long as OpenID Connect allows, 255 characters.
  • OpenIdSignInService.SignIn is what an application calls once, with the ID token it got for its person. The first time, it ties the account to the user of its address, on the provider's word that the address is the person's (email_verified), and only to a user that no account is tied to yet. Where AllowSelfRegister is on, someone who is no user yet becomes one then.
  • The ID token must be meant for one of the service's applications, and asked for by one of them. A token says who asked for it (azp) when it is meant for several applications, and may say so anyway: one that another application asked for is refused, though it names one of the service's beside its own, and so is one for several that names nobody.
  • A user is tied to one account, and an account to one user: the table's own keys hold that, also for two sign-ins that come at the same moment.
  • A locked user is tied to no account: the one that tried while the user was locked would be the user's from the day the lock is taken off.
  • The tie of a user that was removed is dropped when its account signs in next, and the account comes as for the first time. Left there, it would keep the person out for good, also once they are made a user again.

๐Ÿ— Repo layout & CI

  • src/ โ€” the packable libraries; one shared version and package metadata via src/Directory.Build.props. pub/PubVersion.json is the version source of truth.
  • tests/ โ€” test suites and sample hosts. Never packed.
  • .github/workflows/ โ€” thin wrappers over the reusable CI in GrayMint.Common: every push to main builds, tests, bumps the version, and publishes to nuget.org; a daily job (02:30 UTC, right after GrayMint.Common's own update) upgrades all NuGet dependencies and republishes when tests pass. Nothing ships when tests fail.

Build locally:

dotnet build GrayMint.Authorization.slnx
dotnet test GrayMint.Authorization.slnx

๐Ÿ“„ License

Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on GrayMint.Authorization.RoleManagement.Abstractions:

Package Downloads
GrayMint.Authorization

Reference all GrayMint authorization.

GrayMint.Authorization.RoleManagement.RoleAuthorizations

Package Description

GrayMint.Authorization.RoleManagement.TeamControllers

Package Description

GrayMint.Authorization.RoleManagement.ResourceProviders

Package Description

GrayMint.Authorization.RoleManagement.RoleProviders

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.209 0 11/17/2026
3.2.208 48 11/17/2026
3.2.207 66 11/16/2026
3.2.206 83 11/13/2026
3.2.205 127 11/12/2026
3.2.204 197 11/11/2026
3.2.203 122 11/11/2026
3.2.202 137 11/10/2026
3.2.201 135 11/9/2026
3.2.199 166 10/31/2026
3.2.198 153 10/30/2026
3.2.197 151 10/29/2026
3.2.196 150 10/28/2026
3.2.195 143 10/28/2026
3.2.194 142 10/26/2026
3.2.193 142 10/26/2026
3.2.192 137 10/26/2026
3.2.191 141 10/24/2026
3.2.190 148 10/21/2026
3.2.189 136 10/21/2026
Loading failed