GrayMint.Authorization.Authentications
3.2.188
dotnet add package GrayMint.Authorization.Authentications --version 3.2.188
NuGet\Install-Package GrayMint.Authorization.Authentications -Version 3.2.188
<PackageReference Include="GrayMint.Authorization.Authentications" Version="3.2.188" />
<PackageVersion Include="GrayMint.Authorization.Authentications" Version="3.2.188" />
<PackageReference Include="GrayMint.Authorization.Authentications" />
paket add GrayMint.Authorization.Authentications --version 3.2.188
#r "nuget: GrayMint.Authorization.Authentications, 3.2.188"
#:package GrayMint.Authorization.Authentications@3.2.188
#addin nuget:?package=GrayMint.Authorization.Authentications&version=3.2.188
#tool nuget:?package=GrayMint.Authorization.Authentications&version=3.2.188
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 newAudience.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:
IRoleProviderIUserProviderIResourceProvider
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.
๐ Repo layout & CI
src/โ the packable libraries; one shared version and package metadata viasrc/Directory.Build.props.pub/PubVersion.jsonis 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 tomainbuilds, 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 | Versions 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. |
-
net10.0
- GrayMint.Authorization.Abstractions (>= 3.2.188)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.13)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on GrayMint.Authorization.Authentications:
| Package | Downloads |
|---|---|
|
GrayMint.Authorization
Reference all GrayMint authorization. |
|
|
GrayMint.Authorization.RoleManagement.TeamControllers
Package Description |
|
|
GrayMint.Authorization.Authentications.Controllers
Package Description |
|
|
GrayMint.Authorization.MicroserviceAuthorization
GrayMint Authorization for microservices |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.2.188 | 0 | 10/21/2026 |
| 3.2.187 | 91 | 10/18/2026 |
| 3.2.186 | 128 | 10/14/2026 |
| 3.2.185 | 110 | 10/13/2026 |
| 3.2.184 | 128 | 10/8/2026 |
| 3.2.183 | 122 | 10/7/2026 |
| 3.2.182 | 125 | 10/2/2026 |
| 3.2.181 | 129 | 10/1/2026 |
| 3.2.180 | 134 | 9/30/2026 |
| 3.2.179 | 389 | 9/28/2026 |
| 3.2.178 | 137 | 9/26/2026 |
| 3.2.177 | 128 | 9/25/2026 |
| 3.2.176 | 135 | 9/23/2026 |
| 3.2.175 | 135 | 9/22/2026 |
| 3.2.174 | 135 | 9/19/2026 |
| 3.2.173 | 131 | 9/17/2026 |
| 3.2.172 | 130 | 9/16/2026 |
| 3.2.171 | 282 | 9/10/2026 |
| 3.2.170 | 152 | 9/9/2026 |
| 3.2.169 | 146 | 9/8/2026 |