第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 identiyserver4 授權 signalr core hub

使用 identiyserver4 授權 signalr core hub

C#
慕桂英3389331 2023-09-24 10:55:16
我正在使用具有單獨授權的 Visual Studio 2019 預覽版 Angular / .net core API 后端模板。我相信在這個模板中,正在使用identityserver4。在 API 中,有一個我正在嘗試授權的信號器核心中心。我在集線器上有授權屬性。我還在 Angular Signalr 客戶端 URL 查詢字符串中指定了令牌。盡管存在上述情況,授權屬性沒有任何作用,我可以使用或不使用令牌訪問集線器。JS / 角度客戶端ngOnInit() {console.log(this.authService.getAccessToken().toPromise())this._hubConnection = new signalR.HubConnectionBuilder()  //.withUrl('/handoverhub', {accessTokenFactory: () => this.token})  .withUrl('/handoverhub', { accessTokenFactory: () => {    return this.authService.getAccessToken().toPromise();  } })  .configureLogging(signalR.LogLevel.Information)  .build();使用 Microsoft.AspNetCore.SignalR 的 ASPNETCore 代碼中心;using System; using System.Collections.Generic; using System.Diagnostics;using System.Linq;using System.Security.Claims;using System.Threading.Tasks;using HomecareShared.Models;using HomecareShared.Models.DTOs;using HomecareShared.Models.Handover;using HomecareShared.Models.Notify;using HomecareShared.Models.SharedResources;using HomecareHandover.Repo;using Microsoft.AspNetCore.Authentication.JwtBearer;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Identity;using Microsoft.AspNetCore.Identity.EntityFrameworkCore;using Microsoft.VisualBasic.ApplicationServices;namespace HomecareHandover.Hubs {[Authorize]public class HandoverHub : Hub一些啟動的片段        app.UseAuthentication();        app.UseAuthorization();        app.UseRouting();        app.UseEndpoints(endpoints =>        {            endpoints.MapHub<HandoverHub>("/handoverhub"); //For handover             endpoints.MapHub<TaskHub>("/taskhub"); //For task        });        app.UseIdentityServer();   services.AddAuthentication()            .AddIdentityServerJwt();        services.AddSignalR();沒有錯誤消息。我可以直接進入集線器,沒有問題。
查看完整描述

2 回答

?
慕神8447489

TA貢獻1780條經(jīng)驗 獲得超1個贊

我也遇到過類似的問題,但是使用AzureSignalR. 我通過實現(xiàn)下面的代碼解決了這個問題。您還應該UseIdentityServer先打電話UseEndpoints;


app.UseAuthentication();

app.UseAuthorization();

app.UseAzureSignalR(routes =>

{

    routes.MapHub<ChatHub>("/hubs/chat");

    routes.MapHub<NotificationHub>("/hubs/notifications");

});

app.UseEndpoints(endpoints =>

{

    endpoints.MapDefaultControllerRoute();

    endpoints.MapHealthChecks("/healthz", new HealthCheckOptions() { });

});

順便說一句,另一個關于 AzureSignalR 和純 JWT 中的集線器授權的示例,但我放在這里,以便您可以查看 https://github.com/ilkerkaran/MySignalRPlayGround/blob/master/SignalRServer.API/Startup.cs


查看完整回答
反對 回復 2023-09-24
?
慕仙森

TA貢獻1827條經(jīng)驗 獲得超8個贊

固定的?。。?!

原來它是在 Startup.cs 文件中排序的。

我首先實現(xiàn)了ilkerkaran關于在UseEndpoints之前調(diào)用identityserver的建議。然后又過了 4 個小時,我將 app.UseAuthorization() 移到了 app.UseIdentityServer 下面并修復了它。

希望這對其他人有幫助。


查看完整回答
反對 回復 2023-09-24
  • 2 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號