ManagedCode.Orleans.Identity.Core 9.0.1

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

<img alt="managed code Identity" src="https://github.com/managed-code-hub/Identity/raw/main/logo.png" width="300px" />

Orleans.Identity

Orleans.Identity expands ASP.NET Core authentication and authorization into Orleans grains. It forwards the ClaimsPrincipal created by ASP.NET Identity (JWT, cookies, etc.) to grains, validates [Authorize] attributes inside the cluster, and exposes helpers that make the current user available inside grain code.

The repository ships three NuGet packages:

Package Purpose
ManagedCode.Orleans.Identity.Server Registers an Orleans incoming grain call filter that enforces ASP.NET Core authorization attributes in the silo.
ManagedCode.Orleans.Identity.Client Adds MVC and SignalR filters that copy the authenticated ClaimsPrincipal into Orleans RequestContext before grains are invoked.
ManagedCode.Orleans.Identity.Core Shared helpers (claim surrogates, extensions, constants).

Key capabilities

  • Authorization parity with ASP.NET Core – Grains honor [Authorize], [AllowAnonymous], and role restrictions declared on grains or grain interfaces. Unauthorized calls throw UnauthorizedAccessException before grain logic runs.
  • Automatic claim propagation – HTTP controllers and SignalR hubs copy the authenticated user into Orleans RequestContext so that the grain filter can evaluate claims and roles consistently.
  • Grain-side helpers – Call this.GetCurrentUser() inside a grain to access the caller’s ClaimsPrincipal without repeating boilerplate request-context lookups.
  • SignalR and REST coverage – Integration tests verify JWT, cookie, and SignalR scenarios end-to-end with role checks and anonymous access rules.

Getting started

1. Configure the Orleans silo

var host = Host.CreateDefaultBuilder(args)
    .UseOrleans(siloBuilder =>
    {
        siloBuilder
            .UseLocalhostClustering()
            .AddOrleansIdentity(); // registers the authorization grain filter
    })
    .Build();

await host.RunAsync();

The extension registers GrainAuthorizationIncomingFilter, which inspects grain metadata and enforces ASP.NET authorization attributes inside the silo.

2. Configure the ASP.NET Core host

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddSignalR();

// Add authentication (JWT, cookies, etc.)
builder.Services.AddAuthentication(/* your schemes */);

// Forward ClaimsPrincipal values to Orleans
builder.Services.AddOrleansIdentity();

builder.Services.AddOrleansClient(client =>
{
    client.UseLocalhostClustering();
});

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.MapHub<ChatHub>("/chat");

app.Run();

The MVC and SignalR filters installed by AddOrleansIdentity push the authenticated user into RequestContext whenever a controller action or hub method is invoked.

3. Enforce authorization in grains

[Authorize]
public interface IUserGrain : IGrainWithGuidKey
{
    Task<string> GetProfileAsync();

    [Authorize(Roles = "Admin")]
    Task<string> GetAdminPanelAsync();
}

public class UserGrain : Grain, IUserGrain
{
    public Task<string> GetProfileAsync()
    {
        var user = this.GetCurrentUser();
        return Task.FromResult($"Hello, {user.Identity?.Name ?? "anonymous"}!");
    }

    public Task<string> GetAdminPanelAsync()
    {
        return Task.FromResult("Admin only data");
    }
}

When the grain call arrives, the filter validates the caller’s authentication state and roles before executing grain logic, and the grain extension retrieves the caller’s claims for business logic.

Testing

Run the integration suite to exercise the ASP.NET + Orleans pipeline:

dotnet test

The tests spin up an Orleans test cluster and an ASP.NET Core host to validate JWT, cookie, and SignalR flows, including role checks and anonymous endpoints.

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 (2)

Showing the top 2 NuGet packages that depend on ManagedCode.Orleans.Identity.Core:

Package Downloads
ManagedCode.Orleans.Identity.Client

Identity base on Orleans

ManagedCode.Orleans.Identity.Server

Identity base on Orleans

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.1 226 11/2/2025
9.0.0 174 7/31/2025
8.0.1 163 7/31/2025
8.0.0 579 12/7/2023
7.0.5 624 7/13/2023
7.0.4 538 7/12/2023
7.0.3 573 6/27/2023
7.0.2 562 4/20/2023
7.0.1 327 4/17/2023