ManagedCode.Orleans.Identity.Client 9.0.0

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

A simplified Orleans library for handling authorization context propagation from ASP.NET Core controllers and SignalR hubs to Orleans grains.

Overview

This library provides a simple way to pass user authorization context from your ASP.NET Core application to Orleans grains, allowing you to implement authorization at the grain level using standard ASP.NET Core authorization attributes.

Features

  • JWT-based authentication: Works with standard JWT tokens
  • Controller authorization: Automatically passes user claims to grains called from controllers
  • SignalR authorization: Supports authorization in SignalR hubs
  • Grain-level authorization: Use [Authorize] and [Authorize(Roles = "RoleName")] attributes on grains
  • Simple grain extension: Use this.GetCurrentUser().Claims to access user claims in grains

Quick Start

1. Orleans Cluster Setup

var builder = Host.CreateDefaultBuilder(args)
    .UseOrleans(siloBuilder =>
    {
        siloBuilder
            .UseLocalhostClustering()
            .AddOrleansIdentity(); // Add the authorization filter;
    });

2. ASP.NET Core API Setup

var builder = WebApplication.CreateBuilder(args);

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

// Add Orleans Identity
builder.Services.AddOrleansIdentity();

// Add JWT authentication
builder.Services.AddAuthentication("Bearer")
    .AddJwtBearer("Bearer", options => { /* JWT configuration */ });

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();
app.UseOrleansIdentity(); // Add the middleware

app.MapControllers();
app.MapHub<YourHub>("/hub");

3. Using in Grains

[Authorize]
public class MyGrain : Grain, IMyGrain
{
    [AllowAnonymous]
    public Task<string> GetPublicInfo()
    {
        return Task.FromResult("Public info");
    }

    [Authorize]
    public Task<string> GetUserInfo()
    {
        var user = this.GetCurrentUser();
        var username = user.FindFirst(ClaimTypes.Name)?.Value;
        return Task.FromResult($"Hello, {username}!");
    }

    [Authorize(Roles = "Admin")]
    public Task<string> GetAdminInfo()
    {
        return Task.FromResult("Admin only info");
    }
}

Testing

The library includes comprehensive integration tests in the ManagedCode.Orleans.Identity.Tests project that demonstrate:

  • JWT token generation and validation
  • Controller → Grain authorization flow
  • SignalR → Grain authorization flow
  • Role-based access control
  • Grain authorization with user claims

Running Tests

dotnet test

Test Structure

The tests use the existing integration test infrastructure with:

  • TestApp: ASP.NET Core application with controllers and SignalR hubs
  • Cluster: Orleans test cluster with grains
  • Integration Tests: Comprehensive tests covering all scenarios

Architecture

The library works by:

  1. Middleware: Extracts user claims from JWT tokens and stores them in Orleans RequestContext
  2. SignalR Filter: Handles authorization in SignalR hubs and stores claims in RequestContext
  3. Grain Filter: Intercepts grain calls and validates authorization based on [Authorize] attributes
  4. Grain Extension: Provides this.GetCurrentUser() method to access claims in grains

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

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
9.0.0 101 7/31/2025
8.0.1 100 7/31/2025
8.0.0 468 12/7/2023
7.0.5 695 7/13/2023
7.0.4 543 7/12/2023
7.0.3 651 6/27/2023
7.0.2 617 4/20/2023
7.0.1 675 2/7/2023
7.0.0 742 1/17/2023