对于未经授权的 Web api 调用,Openiddict 返回 404 而不是 401(核心 2.0)
Openiddict returning 404 instead of 401 for unauthorized web api calls (core 2.0)
我已经在 .net core 2.0 web 中设置了 openiddict api 并且代码和密码流可以正常工作。我有测试用例来确保 API 中的锁定操作在请求者未经授权查找 401 状态代码时被拒绝。
当这些测试 运行 时,响应是 404 not found 而不是 401,这使我的测试失败。我知道路线是正确的,因为它 returns 200 当它允许匿名时。每当我尝试访问任何未经身份验证而锁定的操作时,我都会收到 404。当您尝试在未经身份验证的情况下访问资源时,这是 openiddict 的默认状态吗?无论是 运行 来自浏览器、邮递员还是来自测试用例,都会发生此行为。如何将其配置为 return 401?我在下面提供了我的配置。
services.AddOpenIddict<int>(options =>
{
options.AddEntityFrameworkCoreStores<ApplicationContext>();
options.AddMvcBinders();
options.EnableAuthorizationEndpoint("/connect/authorize");
options.EnableTokenEndpoint("/connect/token");
options.AllowAuthorizationCodeFlow();
options.AllowPasswordFlow();
options.AllowRefreshTokenFlow();
options.RequireClientIdentification();
options.SetAccessTokenLifetime(TimeSpan.FromMinutes(1));
options.SetRefreshTokenLifetime(TimeSpan.FromMinutes(20160));
options.DisableHttpsRequirement();
});
services.AddAuthentication()
.AddFacebook(o => { o.ClientId = settings.FacebookAppID; o.ClientSecret = settings.FacebookAppSecret; })
.AddOAuthValidation();
通过指定对 oauth 的默认质询,我能够获得所需的 401。仍然很高兴知道它试图重定向到哪里。
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = OAuthValidationDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = OAuthValidationDefaults.AuthenticationScheme;
})
.AddFacebook(o => { o.ClientId = settings.FacebookAppID; o.ClientSecret = settings.FacebookAppSecret; })
.AddOAuthValidation();
我已经在 .net core 2.0 web 中设置了 openiddict api 并且代码和密码流可以正常工作。我有测试用例来确保 API 中的锁定操作在请求者未经授权查找 401 状态代码时被拒绝。
当这些测试 运行 时,响应是 404 not found 而不是 401,这使我的测试失败。我知道路线是正确的,因为它 returns 200 当它允许匿名时。每当我尝试访问任何未经身份验证而锁定的操作时,我都会收到 404。当您尝试在未经身份验证的情况下访问资源时,这是 openiddict 的默认状态吗?无论是 运行 来自浏览器、邮递员还是来自测试用例,都会发生此行为。如何将其配置为 return 401?我在下面提供了我的配置。
services.AddOpenIddict<int>(options =>
{
options.AddEntityFrameworkCoreStores<ApplicationContext>();
options.AddMvcBinders();
options.EnableAuthorizationEndpoint("/connect/authorize");
options.EnableTokenEndpoint("/connect/token");
options.AllowAuthorizationCodeFlow();
options.AllowPasswordFlow();
options.AllowRefreshTokenFlow();
options.RequireClientIdentification();
options.SetAccessTokenLifetime(TimeSpan.FromMinutes(1));
options.SetRefreshTokenLifetime(TimeSpan.FromMinutes(20160));
options.DisableHttpsRequirement();
});
services.AddAuthentication()
.AddFacebook(o => { o.ClientId = settings.FacebookAppID; o.ClientSecret = settings.FacebookAppSecret; })
.AddOAuthValidation();
通过指定对 oauth 的默认质询,我能够获得所需的 401。仍然很高兴知道它试图重定向到哪里。
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = OAuthValidationDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = OAuthValidationDefaults.AuthenticationScheme;
})
.AddFacebook(o => { o.ClientId = settings.FacebookAppID; o.ClientSecret = settings.FacebookAppSecret; })
.AddOAuthValidation();