From d1b230f5ff64cff4f158f46177f195b1531815df Mon Sep 17 00:00:00 2001 From: niyyzf Date: Sat, 29 Jun 2024 19:01:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9webscort=E5=81=A5=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LoongPanel-Asp/Middlewares/PermissionMiddleware.cs | 12 ++++++++---- LoongPanel-Asp/Properties/launchSettings.json | 6 +++--- web/strores/HubStore.ts | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/LoongPanel-Asp/Middlewares/PermissionMiddleware.cs b/LoongPanel-Asp/Middlewares/PermissionMiddleware.cs index 6226f00..36627c7 100755 --- a/LoongPanel-Asp/Middlewares/PermissionMiddleware.cs +++ b/LoongPanel-Asp/Middlewares/PermissionMiddleware.cs @@ -39,10 +39,14 @@ public class PermissionMiddleware( if (string.IsNullOrEmpty(cookieToken)) { - //如果Cookie中也没有Token,则返回401 Unauthorized - logger.LogWarning("Token not found in Authorization header or cookie."); - context.Response.StatusCode = StatusCodes.Status401Unauthorized; - return; + cookieToken = context.Request.Query["access_token"]; + if (string.IsNullOrEmpty(cookieToken)) + { + //如果Cookie中也没有Token,则返回401 Unauthorized + logger.LogWarning("Token not found in Authorization header or cookie."); + context.Response.StatusCode = StatusCodes.Status401Unauthorized; + return; + } } token = cookieToken; diff --git a/LoongPanel-Asp/Properties/launchSettings.json b/LoongPanel-Asp/Properties/launchSettings.json index d43adb8..be89b84 100755 --- a/LoongPanel-Asp/Properties/launchSettings.json +++ b/LoongPanel-Asp/Properties/launchSettings.json @@ -4,7 +4,7 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://192.168.0.13:58826", + "applicationUrl": "http://127.0.0.1:58826", "sslPort": 44304 } }, @@ -14,7 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": false, "launchUrl": "swagger", - "applicationUrl": "http://192.168.0.13:5253", + "applicationUrl": "http://127.0.0.1:5253", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -24,7 +24,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://192.168.0.13:7233;http://192.168.0.13:5253", + "applicationUrl": "https://127.0.0.1:7233;http://127.0.0.1:5253", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/web/strores/HubStore.ts b/web/strores/HubStore.ts index e26fe3a..fe26464 100755 --- a/web/strores/HubStore.ts +++ b/web/strores/HubStore.ts @@ -15,7 +15,9 @@ export const useSessionSignalRStore = defineStore('sessionSignalR', { initConnection() { // 构建连接 this.connection = new HubConnectionBuilder() - .withUrl(`${useRuntimeConfig().public.baseUrl}/SessionHub`) + .withUrl(`${useRuntimeConfig().public.baseUrl}/SessionHub`,{ + accessTokenFactory:()=> `${useCookie('token').value}` + }) .withAutomaticReconnect() .build();