小编Ama*_*ika的帖子

在ASP.NET上配置DefaultScheme和DefaultChallegeScheme有什么意义?

我正在学习ASP.NET Core 2.0和IdentityServer4上的安全性.我使用IdentityServer,Api和ASP.NET MVC Client App设置项目.

ConfigureServiceClient App上的方法如下所示.在这里,我的困惑DefaultSchemeDefaultChallegeScheme.配置那些有什么意义?如果可能的话,关于它如何工作的详细描述将非常有用.

我已经看到了DefaultScheme,DefaultSignScheme但也有效,但它是如何工作的?这些有什么区别?

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

    services.AddAuthentication(options =>
    {
        options.DefaultScheme = "Cookies";
        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        //options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        //options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddCookie("Cookies")
    .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
    {
        options.SignInScheme = "Cookies";
        options.RequireHttpsMetadata = false;

        options.Authority = "http://localhost:5000/";
        options.ClientId = "mvcclient";
        options.SaveTokens = true;
    });
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-authentication asp.net-core identityserver4

8
推荐指数
1
解决办法
2085
查看次数

为什么使用 Identity Server 和 asp.net core 2 在基于令牌的身份验证上使用 cookie

我正在创建一个示例应用程序,以了解身份服务器 4 身份验证如何与 Asp.net core 2 一起工作。我注意到为不同级别生成了一些 cookie,如所附屏幕截图所示。我的问题是为什么会生成这些 cookie?

下面的语句,我取自 Identity Server 文档。身份服务器配置时

IdentityServer 使用自定义方案(通过常量 IdentityServerConstants.DefaultCookieAuthenticationScheme)在内部调用 AddAuthentication 和 AddCookie,

这里为什么它调用AddCookies身份服务器本身的方法?

此外,当我将 Asp.net 核心 Web 客户端配置为使用身份服务器身份验证时,它也会调用AddCookie()方法。当我尝试对其发表评论时,它会给我一个错误。我有点不清楚这里发生了什么。

身份服务器配置

services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddToDoUserStore()
                .AddInMemoryIdentityResources(Config.GetIdentityResources())
                .AddInMemoryApiResources(Config.GetApiResources())
                .AddInMemoryClients(Config.GetClients());

            services.AddAuthentication("MyCookie")
            .AddCookie("MyCookie", options =>
            {
                options.ExpireTimeSpan = new System.TimeSpan(0, 0, 15);
            });
Run Code Online (Sandbox Code Playgroud)

网页客户端配置

services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options =>
            {
                options.Authority = "https://localhost:44377/";
                options.RequireHttpsMetadata = true;
                options.ClientId = "ToDoTaskManagmentClient";
                options.Scope.Clear();
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.Scope.Add("address");
                options.Scope.Add("roles");
                options.Scope.Add("usertodoapi");
                options.Scope.Add("countries");
                options.Scope.Add("subscriptionlevel"); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-identity identityserver4 asp.net-core-2.0

1
推荐指数
2
解决办法
4889
查看次数