ASP.NET Core 3 中的 app.UseOpenIdConnectAuthentication() 和 OpenIdConnectMiddleware 在哪里?

g.p*_*dou 1 asp.net-core

语境

我正在尝试迁移一个使用app.UseOpenIdConnectAuthentication()但在包中找不到此扩展方法的应用程序此扩展方法Microsoft.AspNetCore.Authentication.OpenIdConnect 的实际来源使用的类OpenIdConnectMiddleware似乎也已消失。

如何迁移此应用程序?

小智 7

将您的启动文件更改为以下示例


public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                options.DefaultAuthenticateScheme = "oidc";
                options.DefaultSignInScheme = "Cookies";
            })
                .AddCookie()
                .AddOpenIdConnect(options =>
                {
                    options.Authority = "http://localhost:5000";
                    options.RequireHttpsMetadata = false;
                    options.ClientId = "mvc-client";
                    options.ClientSecret = "secret-key";
                    options.ResponseType = "id_token token";

                    options.Scope.Add("openid");
                    options.Scope.Add("profile");
                    options.Scope.Add("email");
                });
        }