-
Notifications
You must be signed in to change notification settings - Fork 3
Refactored Orleans.Identity. Removed unnecessary parts, leaved grain … #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c82f17
Refactored Orleans.Identity. Removed unnecessary parts, leaved grain …
VladKovtun99 bfb71cb
Added fixes. Data flow now with ClaimPrincipal, direct exceptions, no…
VladKovtun99 9f62ae6
Added fixes from copilot
VladKovtun99 0f67a27
Small fix of foreach loop.
VladKovtun99 ca46b47
Removed unnecessary variable
VladKovtun99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 0 additions & 56 deletions
56
ManagedCode.Orleans.Identity.Client/Extensions/AuthenticationHandlerExtensions.cs
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
ManagedCode.Orleans.Identity.Client/Extensions/OrleansContextMiddlewareExtensions.cs
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
ManagedCode.Orleans.Identity.Client/Extensions/OrleansIdentityExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using ManagedCode.Orleans.Identity.Client.Middlewares; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.SignalR; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace ManagedCode.Orleans.Identity.Client.Extensions; | ||
|
|
||
| public static class OrleansIdentityExtensions | ||
| { | ||
| public static IServiceCollection AddOrleansIdentity(this IServiceCollection services) | ||
| { | ||
| services.AddScoped<OrleansContextMiddleware>(); | ||
|
|
||
| services.AddSignalR(options => | ||
| { | ||
| options.AddFilter<SignalRAuthorizationFilter>(); | ||
| }); | ||
|
|
||
| return services; | ||
| } | ||
|
|
||
| public static IApplicationBuilder UseOrleansIdentity(this IApplicationBuilder app) | ||
| { | ||
| app.UseMiddleware<OrleansContextMiddleware>(); | ||
|
|
||
| return app; | ||
| } | ||
| } |
14 changes: 10 additions & 4 deletions
14
ManagedCode.Orleans.Identity.Client/Middlewares/OrleansContextMiddleware.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,20 @@ | ||
| using System.Security.Claims; | ||
| using System.Threading.Tasks; | ||
| using ManagedCode.Orleans.Identity.Core.Extensions; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Orleans.Runtime; | ||
| using ManagedCode.Orleans.Identity.Core.Constants; | ||
|
|
||
| namespace ManagedCode.Orleans.Identity.Client.Middlewares; | ||
|
|
||
| public class OrleansContextMiddleware(RequestDelegate next) | ||
| public class OrleansContextMiddleware : IMiddleware | ||
| { | ||
| public async Task InvokeAsync(HttpContext context) | ||
| public async Task InvokeAsync(HttpContext context, RequestDelegate next) | ||
| { | ||
| context.User.SetOrleansContext(); | ||
| if (context.User.Identity?.IsAuthenticated == true) | ||
| { | ||
| RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, context.User); | ||
| } | ||
|
|
||
| await next(context); | ||
| } | ||
| } |
73 changes: 0 additions & 73 deletions
73
ManagedCode.Orleans.Identity.Client/Middlewares/OrleansIdentityAuthenticationHandler.cs
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
ManagedCode.Orleans.Identity.Client/Middlewares/SignalRAuthorizationFilter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.SignalR; | ||
| using Orleans.Runtime; | ||
| using ManagedCode.Orleans.Identity.Core.Constants; | ||
|
|
||
| namespace ManagedCode.Orleans.Identity.Client.Middlewares; | ||
|
|
||
| public class SignalRAuthorizationFilter : IHubFilter | ||
| { | ||
| public async ValueTask<object?> InvokeMethodAsync( | ||
| HubInvocationContext invocationContext, | ||
| Func<HubInvocationContext, ValueTask<object?>> next) | ||
| { | ||
| if (invocationContext.Context.User?.Identity?.IsAuthenticated == true) | ||
| { | ||
| RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, invocationContext.Context.User); | ||
| } | ||
|
|
||
| return await next(invocationContext); | ||
| } | ||
|
|
||
| public Task OnConnectedAsync(HubLifetimeContext context, Func<HubLifetimeContext, Task> next) | ||
| { | ||
| if (context.Context.User?.Identity?.IsAuthenticated == true) | ||
| { | ||
| RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, context.Context.User); | ||
| } | ||
|
|
||
| return next(context); | ||
| } | ||
|
|
||
| public Task OnDisconnectedAsync(HubLifetimeContext context, Exception? exception, Func<HubLifetimeContext, Exception?, Task> next) | ||
| { | ||
| return next(context, exception); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
ManagedCode.Orleans.Identity.Core/Extensions/GrainExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using System; | ||
| using System.Security.Claims; | ||
| using Orleans; | ||
| using Orleans.Runtime; | ||
| using ManagedCode.Orleans.Identity.Core.Constants; | ||
|
|
||
| namespace ManagedCode.Orleans.Identity.Core.Extensions; | ||
|
|
||
| public static class GrainExtensions | ||
| { | ||
| public static ClaimsPrincipal GetCurrentUser(this Grain grain) | ||
| { | ||
| var requestContext = RequestContext.Get(OrleansIdentityConstants.USER_CLAIMS); | ||
| return requestContext as ClaimsPrincipal ?? new ClaimsPrincipal(new ClaimsIdentity()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
ManagedCode.Orleans.Identity.Core/Serializations/ClaimsPrincipalSurrogate.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using System.Collections.Generic; | ||
| using System.Security.Claims; | ||
| using Orleans; | ||
|
|
||
| namespace ManagedCode.Orleans.Identity.Core.Serializations; | ||
|
|
||
| // This is the surrogate which will act as a stand-in for the foreign type. | ||
| // Surrogates should use plain fields instead of properties for better performance. | ||
| [GenerateSerializer] | ||
| public struct ClaimsPrincipalSurrogate(List<ClaimsIdentity>? identities, string? primaryIdentityType) | ||
| { | ||
| [Id(0)] | ||
| public List<ClaimsIdentity>? Identities { get; set; } = identities; | ||
|
|
||
| [Id(1)] | ||
| public string? PrimaryIdentityType { get; set; } = primaryIdentityType; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.