MatinDeWet.Identification 1.0.2

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

Identification

NuGet Version CI Status Publish Status

A lightweight .NET class library for claim-based identity access with configurable ID parsing and simple DI wiring.

Features

  • Read user identity data from claims through one interface.
  • Configure claim names and parsing logic in DI.
  • Use strongly typed IDs with IIdentityInfo<TExternalUserId, TInternalUserId>.
  • Or inject the simpler non-generic IIdentityInfo when preferred.

Installation

dotnet add package MatinDeWet.Identification

Quick Start

  1. Register the package in DI (explicit configuration is required).
  2. Populate IInfoSetter from the current request claims.
  3. Inject IIdentityInfo or IIdentityInfo<TExternalUserId, TInternalUserId> in your services.

1) Register In DI

using Identification.Base.Contracts;
using Identification.Core;

services.AddIdentificationSupport<long, int>(options =>
{
	options.ExternalUserIdClaimType = "external_user_id";
	options.InternalUserIdClaimType = "user_id";
	options.RoleClaimType = "role";
	options.AdminRoleValue = "Admin";
	options.ExternalUserIdParser = value => long.Parse(value);
	options.InternalUserIdParser = value => int.Parse(value);
});

2) Populate Claim Data Per Request

The package reads claims from IInfoSetter, so set those claims early in the pipeline.

using Identification.Base.Contracts;

app.Use(async (context, next) =>
{
	IInfoSetter infoSetter = context.RequestServices.GetRequiredService<IInfoSetter>();
	infoSetter.SetUser(context.User.Claims);
	await next();
});

3) Inject And Use

Typed usage:

using Identification.Base.Contracts;

public sealed class TypedIdentityService
{
	private readonly IIdentityInfo<long, int> _identityInfo;

	public TypedIdentityService(IIdentityInfo<long, int> identityInfo)
	{
		_identityInfo = identityInfo;
	}

	public (long externalId, int internalId, bool isAdmin) ReadIdentity()
	{
		long externalId = _identityInfo.GetExternalUserId();
		int internalId = _identityInfo.GetInternalUserId();
		bool isAdmin = _identityInfo.IsAdmin();

		return (externalId, internalId, isAdmin);
	}
}

Non-generic usage:

using Identification.Base.Contracts;

public sealed class MyService
{
	private readonly IIdentityInfo _identityInfo;

	public MyService(IIdentityInfo identityInfo)
	{
		_identityInfo = identityInfo;
	}

	public bool CanAccessAdmin()
	{
		return _identityInfo.IsAdmin();
	}

	public long GetExternalId()
	{
		long externalId = _identityInfo.GetExternalUserId();
		return externalId;
	}
}

You can also read as other supported types directly:

Guid externalId = identityInfo.GetExternalUserId();
int internalId = identityInfo.GetInternalUserId();
string externalIdRaw = identityInfo.GetExternalUserId();

Configuration Reference

IdentificationOptions<TExternalUserId, TInternalUserId>

  • ExternalUserIdClaimType: Claim type name for external user ID. Required.
  • InternalUserIdClaimType: Claim type name for internal user ID. Required.
  • RoleClaimType: Claim type used for role checks. Optional. Defaults to ClaimTypes.Role if not set.
  • AdminRoleValue: Role value considered admin. Required.
  • ExternalUserIdParser: Converts claim value into TExternalUserId. Optional. Default parser is provided.
  • InternalUserIdParser: Converts claim value into TInternalUserId. Optional. Default parser is provided.

Public Interface Methods

IIdentityInfo<TExternalUserId, TInternalUserId>

  • GetExternalUserId()
  • GetInternalUserId()
  • IsAdmin()
  • HasRole(string role)
  • HasValue(string claimType)
  • GetValue(string claimType)

IIdentityInfo

  • GetExternalUserId() returns IdentityValue (implicitly convertible to string, Guid, long, int)
  • GetInternalUserId() returns IdentityValue (implicitly convertible to string, Guid, long, int)
  • IsAdmin()
  • HasRole(string role)
  • HasValue(string claimType)
  • GetValue(string claimType)

Notes

  • If claim values are missing or invalid for your parser, methods throw InvalidOperationException.
  • Keep your parser functions aligned with the claim formats emitted by your identity provider.
  • Prefer typed interface injection when you want compile-time ID types.

Compile-Time Safety Without Repeating Generics

If you want compile-time safety and still inject IIdentityInfo-style names in your app code, create a global alias in your consuming project:

// GlobalUsings.cs in your application
global using IIdentityInfo = Identification.Base.Contracts.IIdentityInfo<long, int>;

Then in services/controllers you can use:

private readonly IIdentityInfo _identityInfo;

This keeps compile-time typed IDs while avoiding repeated generic type arguments everywhere.

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.2 98 6/13/2026
1.0.1 103 6/8/2026
1.0.0 93 6/8/2026