【问题标题】:ABP 401 response from API instead of redirect来自 API 的 ABP 401 响应而不是重定向
【发布时间】:2017-07-17 12:41:07
【问题描述】:

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

我正在使用 Web.Mvc 项目作为我的启动项目,我想进行 API 调用。

当我对 API 执行未经授权的请求时,我得到的是“200 OK”响应而不是“401”。我在哪里做错了?

【问题讨论】:

标签: asp.net-core aspnetboilerplate asp.net-core-identity


【解决方案1】:

ASP.NET Core 1.x

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

.Core项目中修改IdentityRegistrar

// 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

ASP.NET Core 2.0

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

.Web.Mvc / .Web.Host 项目中修改AuthConfigurer

// Before
services.AddAuthentication()

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

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

【讨论】:

    【解决方案2】:

    这个authorization 文档将为您提供每一个细节。

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    猜你喜欢
    • 2013-09-10
    • 1970-01-01
    • 2016-03-22
    • 2015-08-05
    • 2013-02-12
    • 1970-01-01
    • 2016-07-31
    • 2011-01-04
    • 1970-01-01
    相关资源
    最近更新 更多