[英]How to set Integrated Windows Authentication in SignalR for some but not all hubs
我需要為集線器使用 Windows 身份驗證,但由於我在更大的系統中工作,我只能通過 GlobalHost 訪問 SignalR 管道。
我試過使用AuthorizedAttribute
,但沒有設置身份,因為沒有注冊 Autorization 模塊。
我試過設置GlobalHost.HubPipeline.RequireAuthentication();
這設置了身份,但由於它在全局范圍內設置了授權,因此其他集線器無法連接。
最后,我嘗試添加一個自定義授權模塊,它應該只適用於我想要的一個集線器。 但是,一旦我對一個集線器進行例外處理,就不會再次設置身份,並且我會從授權集線器收到未經授權的響應。
我通常將身份驗證屬性放在集線器 class 的頂部。
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class myChat : Hub
{
}
這是基於令牌的身份驗證,您需要配置從客戶端發送身份驗證令牌。 https://learn.microsoft.com/en-us/as.net/core/signalr/authn-and-authz?view=as.netcore-3.1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.