[英]SignalR core JWT claims
cfg.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
// If the request is for our hub...
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
(path.StartsWithSegments("/sas")))
{
// Read the token out of the query string
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
in my hub i tried to get claims like that 在我的中心,我试图得到这样的要求
Context.User.Claims
but theyre empty 但他们是空的
so is there any option to get my JWT claims in my signalr hub? 所以有什么选择可以让我的JWT索赔进入我的信号中心吗?
I had a similar issue and I've solved it by replacing this: 我有一个类似的问题,我已经通过替换它解决了:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
with this: 有了这个:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
For some reason, I had to explicitly define the DefaultAuthenticateScheme
. 由于某些原因,我必须显式定义
DefaultAuthenticateScheme
。 I still don't know why the DefaultAuthenticateScheme
didn't fallback automatically to the DefaultScheme
as it should according to the documentation. 我仍然不知道为什么
DefaultAuthenticateScheme
不会自动退回到DefaultScheme
,根据文档。 If I find out the reason, I'll update the answer. 如果找出原因,我将更新答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.