gpt4 book ai didi

asp.net-core - 为什么在 ASP.NET Core WebAPI 项目中使用 OAuth2 时会出现 'no authenticationScheme was specified' 错误?

转载 作者:行者123 更新时间:2023-12-02 02:50:24 24 4
gpt4 key购买 nike

我有一个使用 Aurelia 作为前端并使用 ASP.NET Core 作为其 Web API 的应用程序。

我必须在我的 Web API 周围设置一些身份验证和授权。为此,我正在尝试使用 OAuth (Microsoft.Owin.Security.OAuth)。

我有几个问题

  1. 我想知道是否可以仅使用 sql server 数据库中的数据(用户)进行身份验证。所有示例都与 Entity Framework 相关联。因此很难将其分离。

我从一个最低限度的项目开始,刚刚更新了我的入门类(class)。

这是我在启动类中配置服务的方法

services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddOAuth("", Options =>
{
Options.ClientId = "MyApp";
Options.ClientSecret = "MyAppSecret";
Options.CallbackPath = new PathString("//");
Options.AuthorizationEndpoint = "https://localhost:44360/account/authorize";
Options.TokenEndpoint = "https://localhost:44360/account/token";
Options.Events.OnCreatingTicket = async context =>
{

};
Options.Events.OnRemoteFailure = async context =>
{

};
Options.Events.OnTicketReceived = async context =>
{

};
Options.Events.OnRedirectToAuthorizationEndpoint = async context =>
{

};
});
  1. 我添加了默认架构,但仍然出现错误。我错过了什么吗?

错误:

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.

最佳答案

我遇到了同样的问题;我 found another example here并通过向 AddAuthentication() 添加其他选项解决了我的问题:

services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "";
}).AddOAuth("", Options => ...);

关于asp.net-core - 为什么在 ASP.NET Core WebAPI 项目中使用 OAuth2 时会出现 'no authenticationScheme was specified' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52479940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com