-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
IHttpContextAccessor context always null with Azure SignalR Service #17617
Comments
Since the SignalR connection is routed through the Azure SignalR service instead of there being a direct connection to the ASP.NET Core server, there isn't any HttpContext to access. Is there any reason using |
I need to access the access_token to ask another API for the rights this user had based on the claims but the access token is not available in claims. Probably of the other workaround I linked in the original post. |
We generally recommend that you grab the access_token and put it in your claims in middleware before SignalR runs. |
Thanks for both your quick replies! I've spent my morning trying to store the access token as a claim again and seems I was making a stupid (and unrelated) mistake. I was using Just for when someone hits this issue from google, the important pieces of my solution: services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication("Bearer",
options =>
{
options.Authority = "...";
options.ApiName = "...";
options.ApiSecret = "..."; // Do not use 'options.JwtBearerEvents' when using introspection
options.TokenRetriever = CustomTokenRetriever.FromHeaderAndQueryString; // Src: https://github.com/IdentityServer/IdentityServer4/issues/2349#issuecomment-394099795
options.OAuth2IntrospectionEvents = new OAuth2IntrospectionEvents
{
OnTokenValidated = context =>
{
if (!string.IsNullOrWhiteSpace(context.SecurityToken) && context.Principal.Identity is ClaimsIdentity identity && !identity.HasClaim(c => c.Type == "access_token"))
{
identity.AddClaim(new Claim("access_token", context.SecurityToken));
}
return Task.CompletedTask;
}
};
}); |
This feature request is the same as #12535 but unfortunately it's locked (just a few days ago) and I can't comment on it. For security purposes I would like to use the access token in the request (because it's not available in the claims) to get the features a user has access to from another API. The access token is probably not available in the claims because I have another workaround in place from: IdentityServer/IdentityServer4#2349 (comment)
To get the access token, locally (without Azure SignalR service) I use the
IHttpContextAccessor
to access theHttpContext.Request
and get the token but this is not available when using the Azure SignalR service. Is it possible to allow to access theHttpContext
from theIHttpContextAccessor
when using Azure SignalR service?The text was updated successfully, but these errors were encountered: