首页 > 解决方案 > 身份的方案名称是什么?

问题描述

假设我使用以下内容:

services.AddIdentity<User, UserRole>()
        .AddEntityFrameworkStores<AppDbContext>();

正在设置的身份验证方案名称是什么?我在任何文档中都没有找到这个。我试图寻找一个有名字的班级,IdentityAuthenticationDefaultsIdentityDefaults什么也没找到。我已经尝试过“Cookies”,但它没有设置为这个。该应用程序运行良好,因此肯定设置了一些方案名称。

标签: c#asp.net-coreasp.net-identityasp.net-core-identity.net-core-authorization

解决方案


IdentityConstants是您在这里寻找的课程。这是您特定问题的相关部分(已删除 xmldocs):

public class IdentityConstants
{
    private static readonly string CookiePrefix = "Identity";

    public static readonly string ApplicationScheme = CookiePrefix + ".Application";

    ...
}

IdentityConstants.ApplicationScheme用作DefaultAuthenticateScheme- 值本身最终成为Identity.Application.

计划在这里设置:

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme;
    options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme;
    options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})

以下是 API 参考文档的链接:


推荐阅读