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
Provide a way how to get the current ClaimsPrincipal in SignalR core outside of a Hub #18657
Comments
This is recommended approach. Ambient context like Closing as we don't plan to add ambient |
I don't really need the whole HubContext, not even the whole HttpContext, only the current user Principal. I've ended up with this:
This allows me to use the IHttpContextAccessor even with the Azure SignalR service. |
That seems like a fine workaround. Instead of |
I have a SignalR Core hub which has a dependency on a service. That service itself has it's own dependencies and one of them requires access to the current ClaimsPrincipal.
I know, that I can access the ClaimsPrincipal inside the hub using the Context.User property and pass it as a parameter to the service, which can also pass it as a parameter and so on. But I really don't like to pollute the service API by passing this kind of ambient info as a parameter.
I've tried to use the IHttpContextAccessor as described in: https://docs.microsoft.com/en-us/aspnet/core/migration/claimsprincipal-current?view=aspnetcore-2.2 This seems to be working with a simple SignalR setup, but it isn't working with the Azure SignalR service, which will be our production setup.
It would be good to have either the IHttpContextAccessor available in all setups or some other similar interface that would allow to get the current principal.
The text was updated successfully, but these errors were encountered: