Oauth 2.0 在dotnet核心web api项目中使用OAuth2的问题

Oauth 2.0 在dotnet核心web api项目中使用OAuth2的问题,oauth-2.0,asp.net-core-webapi-2.1,Oauth 2.0,Asp.net Core Webapi 2.1,我有一个应用程序,它使用Aurelia作为WEB API的前端和dot net核心 我必须对我的WEB API进行一些身份验证和授权。我正试图使用OAuth(Microsoft.Owin.Security.OAuth)来实现这个目的 我这里有几个问题 我想知道是否可以只使用sql server数据库中的数据(用户)进行身份验证。所有示例都与实体框架相关联。所以我很难做到这一点 我从一个简单的项目开始,刚刚更新了我的入门课程 这是我在startup类中配置服务的方法 services.AddAut

我有一个应用程序,它使用Aurelia作为WEB API的前端和dot net核心

我必须对我的WEB API进行一些身份验证和授权。我正试图使用OAuth(Microsoft.Owin.Security.OAuth)来实现这个目的

我这里有几个问题

  • 我想知道是否可以只使用sql server数据库中的数据(用户)进行身份验证。所有示例都与实体框架相关联。所以我很难做到这一点
  • 我从一个简单的项目开始,刚刚更新了我的入门课程

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

    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 =>
                    {
    
                    };
                });
    
  • 我添加了默认模式,但仍然出现错误。我错过什么了吗
  • 错误

       <ul>
         <li>
              <h2 class="stackerror">InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.
       </h2> 
    <ul>
    
    • InvalidOperationException:未指定authenticationScheme,并且未找到DefaultChallengeScheme。
    这里也有同样的问题。并通过向AddAuthentication()添加其他选项修复了我的问题:


    你解决这个问题了吗?如果是,你能分享你的解决方案吗?
    services.AddAuthentication(options =>
                {
                        options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                        options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                        options.DefaultChallengeScheme = "";
                }).AddOAuth("", Options => ...);