简体   繁体   English

SignalR核心JWT声明

[英]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.

相关问题 如何使用JWT授权SignalR Core Hub方法 - How to authorize SignalR Core Hub method with JWT 来自Angular的SignalR Core中的JWT身份验证 - JWT authentication in SignalR Core from Angular 如何在 OpenIdConnect in.Net Core 中向 Jwt 令牌添加自定义声明 - How to add custom claims to Jwt Token in OpenIdConnect in .Net Core SignalR(.NET Core)中的JWT身份验证,不在Query String中传递令牌 - JWT authentication in SignalR (.NET Core) without passing token in Query String Asp.Net Core 3 Identity - 来自浏览器的 JWT 中不存在自定义声明 - Asp.Net Core 3 Identity - Custom Claims not present in JWT from browser ASP.Net Core MVC / API / SignalR-更改身份验证方案(Cookie和JWT) - ASP.Net Core MVC/API/SignalR - Change authentication schemes (Cookie & JWT) Blazor 服务器 Signalr 集线器缺少用户声明 - Blazor Server Signalr hub is missing user claims SignalR 2绑定到声明中的自定义用户ID - SignalR 2 bind to custom userid from claims 私人和公众对jwt的索赔有什么区别 - What is difference between private and public claims on jwt 验证 JWT 的“iat”和“sub”声明的依据是什么? - What to validate 'iat' and 'sub' claims of a JWT against?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM