Skip to content

Commit 38dcbce

Browse files
committed
some changes
1 parent 47353f5 commit 38dcbce

File tree

46 files changed

+1095
-1027
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1095
-1027
lines changed

.github/workflows/nuget.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup .NET
1818
uses: actions/setup-dotnet@v3
1919
with:
20-
dotnet-version: 8.0.x
20+
dotnet-version: 9.0.x
2121

2222
- name: Restore dependencies
2323
run: dotnet restore
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
using ManagedCode.Orleans.Identity.Client.Middlewares;
1+
using ManagedCode.Orleans.Identity.Client.Filters;
22
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.AspNetCore.SignalR;
45
using Microsoft.Extensions.DependencyInjection;
6+
using Orleans;
7+
using Orleans.Hosting;
58

69
namespace ManagedCode.Orleans.Identity.Client.Extensions;
710

811
public static class OrleansIdentityExtensions
912
{
1013
public static IServiceCollection AddOrleansIdentity(this IServiceCollection services)
1114
{
12-
services.AddScoped<OrleansContextMiddleware>();
15+
// Add the action filter globally for all controllers
16+
services.Configure<MvcOptions>(options =>
17+
{
18+
options.Filters.Add<OrleansAuthorizationActionFilter>();
19+
});
1320

14-
services.AddSignalR(options =>
21+
// Configure SignalR with the authorization filter
22+
services.Configure<HubOptions>(options =>
1523
{
1624
options.AddFilter<SignalRAuthorizationFilter>();
1725
});
26+
1827

1928
return services;
2029
}
21-
22-
public static IApplicationBuilder UseOrleansIdentity(this IApplicationBuilder app)
23-
{
24-
app.UseMiddleware<OrleansContextMiddleware>();
25-
26-
return app;
27-
}
2830
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Mvc.Filters;
3+
using Orleans.Runtime;
4+
using ManagedCode.Orleans.Identity.Core.Constants;
5+
6+
namespace ManagedCode.Orleans.Identity.Client.Filters;
7+
8+
public sealed class OrleansAuthorizationActionFilter : IAsyncActionFilter
9+
{
10+
public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
11+
{
12+
RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, context.HttpContext.User);
13+
return next();
14+
}
15+
}

ManagedCode.Orleans.Identity.Client/Middlewares/SignalRAuthorizationFilter.cs renamed to ManagedCode.Orleans.Identity.Client/Filters/SignalRAuthorizationFilter.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
using System;
2+
using System.Security.Claims;
23
using System.Threading.Tasks;
4+
using ManagedCode.Orleans.Identity.Core.Constants;
35
using Microsoft.AspNetCore.SignalR;
46
using Orleans.Runtime;
5-
using ManagedCode.Orleans.Identity.Core.Constants;
67

7-
namespace ManagedCode.Orleans.Identity.Client.Middlewares;
8+
namespace ManagedCode.Orleans.Identity.Client.Filters;
89

9-
public class SignalRAuthorizationFilter : IHubFilter
10+
public sealed class SignalRAuthorizationFilter : IHubFilter
1011
{
11-
public async ValueTask<object?> InvokeMethodAsync(
12+
public ValueTask<object?> InvokeMethodAsync(
1213
HubInvocationContext invocationContext,
1314
Func<HubInvocationContext, ValueTask<object?>> next)
1415
{
15-
if (invocationContext.Context.User?.Identity?.IsAuthenticated == true)
16-
{
17-
RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, invocationContext.Context.User);
18-
}
19-
20-
return await next(invocationContext);
16+
RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, invocationContext.Context.User!); // can be null
17+
return next(invocationContext);
2118
}
2219

2320
public Task OnConnectedAsync(HubLifetimeContext context, Func<HubLifetimeContext, Task> next)
2421
{
25-
if (context.Context.User?.Identity?.IsAuthenticated == true)
26-
{
27-
RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, context.Context.User);
28-
}
29-
22+
// Don't set RequestContext here as it won't persist to method calls
3023
return next(context);
3124
}
3225

ManagedCode.Orleans.Identity.Client/Middlewares/OrleansContextMiddleware.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

ManagedCode.Orleans.Identity.Core/Constants/OrleansIdentityConstants.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
public static class OrleansIdentityConstants
44
{
5-
public const string SESSION_STORAGE = "sessionStore";
6-
public static string AUTH_TOKEN = "AUTH-TOKEN";
7-
public static string AUTHENTICATION_TYPE = "MC-OrleansIdentity";
8-
public const string SESSION_ID_CLAIM_NAME = "SessionId";
9-
public const string USER_CLAIMS = "UserClaims";
5+
/// <summary>
6+
/// Key used to store user claims in Orleans RequestContext.
7+
/// Works with any ASP.NET Core authentication method (JWT, Cookie, etc.)
8+
/// </summary>
9+
public const string USER_CLAIMS = "MC-UserClaims";
1010
}

ManagedCode.Orleans.Identity.Core/Enums/ResultStatus.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

ManagedCode.Orleans.Identity.Core/Enums/SessionStatus.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

ManagedCode.Orleans.Identity.Core/Extensions/ClaimsPrincipalExtensions.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ public static string GetPhone(this ClaimsPrincipal user)
2525
{
2626
return user.FindFirst(ClaimTypes.HomePhone)?.Value ?? string.Empty;
2727
}
28-
29-
public static string GetSessionId(this ClaimsPrincipal user)
30-
{
31-
return user.FindFirst(OrleansIdentityConstants.SESSION_ID_CLAIM_NAME)?.Value ?? string.Empty;
32-
}
33-
28+
3429
public static string GetGrainId(this ClaimsPrincipal user)
3530
{
3631
return user.FindFirst(ClaimTypes.Actor)?.Value ?? string.Empty;
@@ -40,10 +35,4 @@ public static string[] GetRoles(this ClaimsPrincipal user)
4035
{
4136
return user.FindAll(ClaimTypes.Role).Select(s => s.Value).ToArray();
4237
}
43-
44-
public static bool IsUnauthorizedClient(this ClaimsPrincipal user)
45-
{
46-
//TODO: this is strange
47-
return user.GetGrainId() == OrleansIdentityConstants.AUTH_TOKEN;
48-
}
4938
}

ManagedCode.Orleans.Identity.Core/Extensions/CreateTokenModelExtensions.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)