GM.Identity 1.0.0

dotnet add package GM.Identity --version 1.0.0
                    
NuGet\Install-Package GM.Identity -Version 1.0.0
                    
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="GM.Identity" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GM.Identity" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GM.Identity" />
                    
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 GM.Identity --version 1.0.0
                    
#r "nuget: GM.Identity, 1.0.0"
                    
#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 GM.Identity@1.0.0
                    
#: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=GM.Identity&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GM.Identity&version=1.0.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/gmetskhvarishvili/GM.Identity/master/icon.png" alt="GM.Identity" width="140" height="140" /> </p>

GM.Identity

CI NuGet License: MIT

Identity and access building blocks for GM-based ASP.NET Core apps: PBKDF2 password hashing, secure token generation, claims extraction from the current request, and a rich EF Core domain model for users, roles, permissions, scopes, clients, and sessions. Targets .NET 10.

Packages

The four packages version and release together (lockstep):

Package What it gives you
GM.Identity Runtime primitives: PasswordHasher (PBKDF2), TokenGenerator, and ClaimsExtractor wired to the current HttpContext via AddGMIdentity().
GM.Identity.Domain The identity domain model as EF Core entities — users, roles, permissions, scopes, operations, clients, sessions, and two-factor auth types.
GM.Identity.Persistence EF Core IEntityTypeConfiguration mappings for the domain model against a PostgreSQL schema.
GM.Identity.Gateway Placeholder for the identity gateway/composition layer. Reserved; ships empty for now.
dotnet add package GM.Identity

Quick start

Register

GM.Identity needs the ASP.NET Core HTTP context accessor so ClaimsExtractor can read the current user. Register it once at startup:

using GM.Identity;

builder.Services.AddHttpContextAccessor();
builder.Services.AddGMIdentity();

Hash and verify passwords

PasswordHasher uses PBKDF2 (SHA-256, 100 000 iterations by default) with a per-password random salt, and verifies in constant time.

var (hash, salt) = PasswordHasher.Hash("correct horse battery staple");

// store hash + salt on the user, then later:
bool ok = PasswordHasher.Verify(attempt, hash, salt);

Generate and hash tokens

TokenGenerator produces cryptographically random 64-byte tokens and a SHA-256 hash you can persist instead of the raw token (e.g. for refresh tokens or one-time links).

string token  = TokenGenerator.Generate();  // give this to the client
string stored = TokenGenerator.Hash(token);  // keep this in the database

Read the current identity

Once AddGMIdentity() has run, ClaimsExtractor reads the ambient HttpContext:

Guid?   userId    = ClaimsExtractor.GetUserId();     // ClaimTypes.NameIdentifier
string? username  = ClaimsExtractor.GetUsername();   // ClaimTypes.Name
Guid?   sessionId = ClaimsExtractor.GetSessionId();  // "session_id" claim

Each getter returns null when the claim is absent or malformed, so callers never deal with parse exceptions.

The domain model

GM.Identity.Domain models a full RBAC + client/scope system on top of GM.EntityFramework's SoftDeletableEntity<T> base. The entities are generic (CRTP) so your application closes them with its own concrete types and can extend each one:

  • Users, roles, permissionsGMUser, GMRole, GMPermission, joined by GMUserRole and GMRolePermission. Users carry password hash/salt, email & phone confirmation, lockout, and block state, all mutated through intent-revealing methods (ConfirmEmail(), Block(), IncreaseAccessFailedCount(...), …).
  • Clients, scopes, operationsGMClient, GMScope, GMOperation, joined by GMClientScope and GMScopeOperation, for OAuth-style client/scope authorization.
  • Sessions & two-factorGMUserSession, GMClientSession, GMTwoFactorAuthType, GMUserTwoFactorAuthType.

GM.Identity.Persistence provides matching IEntityTypeConfiguration<T> classes (schema identity) that you apply from your DbContext once you've closed the generics.

Repository layout

GM.Identity/
├── GM.Identity/              # runtime primitives (hashing, tokens, claims, DI)
├── GM.Identity.Domain/       # EF Core domain model (users, roles, scopes, clients, sessions)
├── GM.Identity.Persistence/  # EF Core entity configurations (PostgreSQL)
├── GM.Identity.Gateway/      # reserved gateway/composition layer (empty for now)
└── tests/GM.Identity.Tests/  # xUnit tests for the runtime primitives

Building & testing

dotnet build -c Release
dotnet test  -c Release

Releasing

Versioning is automated from Conventional Commits — see CONTRIBUTING.md. All four packages share one version (Directory.Build.props) and publish together to nuget.org on each release.

License

MIT — see 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 102 8/1/2026