如何使用Identityserver 4获取自定义用户属性?

问题描述 投票:0回答:1

我正在为任务分配Alexa技能。我发现了如何将本地公司的用户帐户与Alexa技能结合在一起。但是现在我需要能够使用该技能中的用户数据。要检索此数据,请致电/ connect / userinfo。但是我只获得某些用户属性,而不是我需要的所有属性。如何做到这一点,以便可以从aspnetUser中检索自定义属性,例如hairColor或其他内容?

我有一个Alexa客户:

new Client
                 {
                     ClientId = "AlexaDev",
                ClientName = "Alexa",
                Enabled = true,
                AllowedGrantTypes = GrantTypes.Code,
                RequireConsent = true,
                AllowRememberConsent = true,
                AllowOfflineAccess = true,
                RefreshTokenExpiration = TokenExpiration.Absolute,
                RefreshTokenUsage = TokenUsage.ReUse,
                AbsoluteRefreshTokenLifetime = 315360000,
                SlidingRefreshTokenLifetime = 31536000,
                ClientSecrets =
                {
                    new Secret("691628AE-4B0D-42F3-BF18-31EDD5F243FD".Sha256())
                },
                AllowedScopes =
                {
                    "AlexaApi", // Mandatory
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                    IdentityServerConstants.StandardScopes.OfflineAccess
                },
                RedirectUris =
                {
                    "https://alexa.amazon.co.jp/api/skill/link/MTT929A6VI81S",
                    "https://layla.amazon.com/api/skill/link/MTT929A6VI81S",
                    "https://pitangui.amazon.com/api/skill/link/MTT929A6VI81S"
                },
                PostLogoutRedirectUris =
                {
                    "https://alexa.amazon.co.jp/api/skill/link/MTT929A6VI81S",
                    "https://layla.amazon.com/api/skill/link/MTT929A6VI81S",
                    "https://pitangui.amazon.com/api/skill/link/MTT929A6VI81S"
                }
            }

和身份追索权

public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            var rolesResource = new IdentityResource
            {
                Name = "roles",
                DisplayName = "Roles",
                Description = "Allow the service access to your user roles.",
                UserClaims = new[] {JwtClaimTypes.Role, ClaimTypes.Role},
                ShowInDiscoveryDocument = true
            };

            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
                new IdentityResources.Email(),
                rolesResource
            };
        }

我需要在此处添加资源发色还是其他方法?在此先感谢

c# asp.net identityserver4 alexa
1个回答
0
投票

一种方法是使用Profile Service在令牌和userinfo端点中包括自定义声明,并且您可以在GetProfileDataAsync方法中查询数据库以获取具有asp.net核心身份的用户信息。 Here是代码示例。

© www.soinside.com 2019 - 2024. All rights reserved.