1

I have an authorization requirement which makes sure the access token in the http header is valid:

class AccessTokenRequirement : AuthorizationHandler<AccessTokenRequirement>, IAuthorizationRequirement 
{
     protected async override Task HandleRequirementAsync(AuthorizationHandlerContext context, AccessTokenRequirement requirement)
     {
         //...
     }
}

I am adding this requirement to the mvc pipeline in the startup.cs class as follows:

services.AddAuthorization(options =>
{
    options.AddPolicy("AccessToken", policy => policy.Requirements.Add(
       services.BuildServiceProvider().GetRequiredService<AccessTokenRequirement>()));
});

I then use this requirement on my signalr hubs like so:

[Authorize(Policy = "AccessToken")]
public class MyHub : Hub

Inside the authorization requirement I check the token and identify the user by hitting the database. My question is how can I access the user details INSIDE the hub methods? What is an elegant way to pass information from inside an authorization requirement to my hub methods? I have read into the Identity concept in asp.net but found it to be difficult to comprehend. Thanks in advance.

1 Answer 1

2

You have access to the ClaimsPrincipal inside your Hub via Context.User.

Is that the information you want or is there something else you want access to in your Hub?

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't realise I could access that from inside my hub, thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.