更新 401鉴权失败情况
This commit is contained in:
parent
36f719370b
commit
04881ef3b8
|
|
@ -51,24 +51,27 @@ namespace Learn.VideoAnalysis.Expand
|
|||
},
|
||||
OnAuthenticationFailed = context =>
|
||||
{
|
||||
context.Response.StatusCode = 403;
|
||||
// 可选:标记一下是否过期
|
||||
if (context.Exception!=null)
|
||||
context.Response.Headers["Token-Expired"] = context.Exception.Message;
|
||||
return Task.CompletedTask;
|
||||
},
|
||||
OnChallenge = context =>
|
||||
{
|
||||
context.HandleResponse();
|
||||
if (context.Response.StatusCode == 403)
|
||||
if (context.Response.Headers.ContainsKey("Token-Expired"))
|
||||
{
|
||||
var data1 = new { Code = 403, Message = context.Error + context.AuthenticateFailure?.Message };
|
||||
context.Response.WriteAsync(data1.ToJson());
|
||||
return Task.CompletedTask;
|
||||
|
||||
}
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "application/json";
|
||||
context.HandleResponse();
|
||||
context.Response.StatusCode = 401;
|
||||
var data = new { Code = 401, Message = context.Error + context.AuthenticateFailure?.Message };
|
||||
context.Response.WriteAsync(data.ToJson());
|
||||
return Task.CompletedTask;
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.Headers["Access-Control-Allow-Origin"] = "*"; // ✅ 补这个
|
||||
var data = new
|
||||
{
|
||||
Code = 401,
|
||||
Message = context.Error + context.AuthenticateFailure?.Message
|
||||
};
|
||||
return context.Response.WriteAsync(data.ToJson());
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -53,9 +53,13 @@ namespace Learn.VideoAnalysis
|
|||
builder.AddAppConfig(args);
|
||||
//初始化 插件
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
//swagger
|
||||
builder.Services.AddSwaggerExpand("AI视频分析");
|
||||
//鉴权
|
||||
builder.Services.AddPermissionAuthentication();
|
||||
//数据库
|
||||
builder.Services.AddSqlSugarExpand();
|
||||
//reids
|
||||
builder.Services.AddRedisExpand();
|
||||
//工作流
|
||||
builder.Services.AddSimpleTexOcrClient();
|
||||
|
|
@ -109,6 +113,8 @@ namespace Learn.VideoAnalysis
|
|||
var app = builder.Build();
|
||||
|
||||
AppCommon.Services = app.Services;
|
||||
//允许跨域
|
||||
app.UseCorsExpand();
|
||||
app.UseMiddleware<BasicAuthMiddleware>("Swagger");
|
||||
// Configure the HTTP request pipeline.
|
||||
app.UseSwagger();
|
||||
|
|
@ -133,7 +139,6 @@ namespace Learn.VideoAnalysis
|
|||
app.MapControllers();
|
||||
|
||||
//自定义 应用
|
||||
app.UseCorsExpand();
|
||||
app.UseSqlSugarExpand();
|
||||
app.UseCoravelExpand();
|
||||
app.UseServiceSystem(() =>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import { useUserStoreHook } from "@/store/modules/user";
|
|||
import router from "@/router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { message } from "../message";
|
||||
import { useNav } from "@/layout/hooks/useNav";
|
||||
|
||||
/**请求后端的地址 未配置则访问BaseURL */
|
||||
const apiServiceConfig = {
|
||||
|
|
@ -203,12 +204,16 @@ class PureHttp {
|
|||
$error.isCancelRequest = Axios.isCancel($error);
|
||||
// 关闭进度条动画
|
||||
NProgress.done();
|
||||
debugger
|
||||
if (error.response?.status === 403) {
|
||||
// 跳转到403页面
|
||||
router.push({
|
||||
path: "/error/403"
|
||||
});
|
||||
} else if (error.response?.status !== 200) {
|
||||
}else if (error.response?.status === 401) {
|
||||
// 跳转到403页面
|
||||
useUserStoreHook().logOut();
|
||||
}else if (error.response?.status !== 200) {
|
||||
ElMessage.warning("请求失败" + $error.message + " ");
|
||||
console.log("请求失败" ,$error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
// 获取配置文件中的允许跨域的地址
|
||||
app.UseCors(options =>
|
||||
{
|
||||
options.WithOrigins("*") // 允许跨域请求的地址
|
||||
options
|
||||
.WithOrigins("*") // 允许跨域请求的地址
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader() // 允许的请求标头
|
||||
.AllowAnyMethod(); // 允许跨域请求的类型 (GET,POST等)
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue