不能在asp.net core 2.0中使用CookieAuthenticaton和openidConnect身份验证

时间:2017-08-28 00:40:33

标签: asp.net-core identityserver4 asp.net-core-mvc-2.0

我已将项目升级到asp.net核心。但是现在我的CookieAuthnetication和OpenIdConnectionAuthentication方法无效。它们已经过时了。

Startup.cs配置方法

 app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
            {
                AuthenticationScheme = "oidc",
                SignInScheme = "Cookies",
                Authority = "http://localhost:5000",
                RequireHttpsMetadata = false,
                ClientId = "integapay.client",
                ClientSecret = "mySecret",
                ResponseType = "code id_token",
                Scope = { "openid", "profile", "api.public", "offline_access" },
                GetClaimsFromUserInfoEndpoint = true,
                SaveTokens = true
            });

1 个答案:

答案 0 :(得分:3)

他们将其转移到Conifguration服务部分

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();      
        services.AddAuthentication(options => {
                        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                    })
        .AddCookie()
        .AddOpenIdConnect(options => SetOpenIdConnectOptions(options));
    }
    private void SetOpenIdConnectOptions(OpenIdConnectOptions options)
    {           
        options.Authority = Configuration["auth:oidc:authority"];
        options.ClientId = Configuration["auth:oidc:clientid"];
        options.RequireHttpsMetadata = false;
        options.ClientSecret = Configuration["auth:oidc:clientSecret"];
        options.SignInScheme = "Cookies";
        options.SaveTokens = true;
        options.GetClaimsFromUserInfoEndpoint = true;
        options.ResponseType = "code id_token";

        options.Scope.Add("openid");
        options.Scope.Add("profile");
        options.Scope.Add("api_back");
        options.Scope.Add("offline_access");
    }

在配置电话中,您只需拨打电话

app.UseAuthentication();

希望这会有所帮助。 :)