【问题标题】:Get Email from IdentityServer 4 using ASPNetIdentity使用 ASPNetIdentity 从 IdentityServer 4 获取电子邮件
【发布时间】:2017-06-13 15:21:49
【问题描述】:

这是我的结构。

-Asp.Net c# Application with IdentityServer 4 用于注册和验证用户。

-Asp.Net C# Web API,提供一些使用 Identity4Server 授权用户的服务

-带有 ocid-client 的 Angular 4 应用程序,使用 ASP.Net C# 应用程序对 Angular 应用程序进行身份验证。

问题: 实际上,当我在 Web API 应用程序中打印经过身份验证的用户声明时,我看不到用户电子邮件。有没有办法在索赔中看到它。

在 WEB API 应用程序中

    if (User.Identity.IsAuthenticated)
    {
        var claims = User.Claims.ToList();
        //Would like to see the User Email Informations
        var AspnetUserId = User.Claims.FirstOrDefault(p => p.Type == "sub").Value;

        this.ContactService.UpdateUserProfile(AspnetUserId,profile);
    }

在 Indentity Server 应用程序中

        new Client
        {
            ClientId = "tgc",
            ClientName = "Tag Twee Client Angular",
            AllowedGrantTypes = GrantTypes.Implicit,

            RequireConsent = false,
            AllowAccessTokensViaBrowser = true,
            RedirectUris = { "http://localhost:5002/login" },
            PostLogoutRedirectUris = { "http://localhost:5002/logout" },
            AllowedCorsOrigins = { "http://localhost:5002" },
            AllowedScopes =
            {
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile,
                "TTAPI",
                IdentityServerConstants.StandardScopes.Email
            }
        }

【问题讨论】:

    标签: asp.net-identity entity-framework-core claims-based-identity identityserver4


    【解决方案1】:

    您需要在 dbo.AspNetUserClaims 中添加值(在 ASPNetIdentity 数据库中) IdentityServer4 将从该表中获取值并设置为用户声明。

    【讨论】:

    • 非常感谢。我添加了值,但它在我的 User.Claims API 中不可见
    • 您是否在 IdentityServer 的 dbo.IdentityResources 和 dbo.IdentityClaims 中添加了范围和声明类型??
    • 是的,我知道,现在我在 API 中看到了一些东西,但是。我只将 Scope 视为声明类型,将电子邮件视为值...
    • ClaimType 存储在表 [IdentityClaims] 中,如 email、email_verified,(email 也是一个 Scope,但包含 email & email_verified 两个 ClaimType),并映射到表 [AspNetUserClaims] 的 ClaimType .
    猜你喜欢
    • 1970-01-01
    • 2018-11-03
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 2016-11-11
    • 1970-01-01
    相关资源
    最近更新 更多