来自API的ABP 401响应,而不是重定向 [英] ABP 401 response from API instead of redirect

查看:314
本文介绍了来自API的ABP 401响应,而不是重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与此相同的问题: https://forum .aspnetboilerplate.com/viewtopic.php?f = 5& t = 4865 ,但是我有带有模块零核心模板的ABP v2.1.

I have the same problem as this: https://forum.aspnetboilerplate.com/viewtopic.php?f=5&t=4865, but I have ABP v2.1 with module-zero-core-template.

我将 Web.Mvc 项目用作启动项目,并且想进行API调用.

I'm using Web.Mvc project as my startup project and I want to make API calls.

当我对API执行未经授权的请求时,我收到的响应是"200 OK",而不是"401".我在哪里弄错了?

When I perform an unauthorized request to the API, I got a "200 OK" response instead of a "401". Where did I make a mistake?

推荐答案

ASP.NET Core 1.x

ABP v2.x/模块零核心模板v2.x

ASP.NET Core 1.x

ABP v2.x / module-zero-core-template v2.x

修改 IdentityRegistrar :

Modify IdentityRegistrar in .Core project:

// Before
services.AddAbpIdentity<Tenant, User, Role>()

// After
services.AddAbpIdentity<Tenant, User, Role>(options =>
{
    options.Cookies.ApplicationCookie.AutomaticChallenge = false;
})

参考: https://github.com/aspnet/Security/issues/804

ABP v3.x/模块零核心模板v3.0.0 – v3.4.0

ABP v3.x / module-zero-core-template v3.0.0 – v3.4.0

修改

Modify AuthConfigurer in .Web.Mvc / .Web.Host project:

// Before
services.AddAuthentication()

// After
services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = "JwtBearer";
    options.DefaultChallengeScheme = "JwtBearer";
})

参考:零模块中的 92b6270 -core-template v3.5.0

Reference: 92b6270 in module-zero-core-template v3.5.0

这篇关于来自API的ABP 401响应,而不是重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆