获取密码流中的声明以及隐式

Get Claims in Password Flow as well as Implicit

我有一个 Angular 9 Web 应用程序通过 oidc-client 连接到 Identity Server 4 和一个 API 使用 Implicit 流程。当我获得经过身份验证的用户时,我可以看到几个我想要的站点声明,例如电子邮件地址、用户名或角色。

我现在正尝试使用密码流程做完全相同的事情,但我只得到 sub 索赔 - 请注意,这是我第一次使用它,因此可能不是是的,但本质上,下面是我正在执行的调用(这次使用 angular-oauth2-oidc 通过我的 ionic 应用程序)——为了简单和测试目的,我使用邮递员来说明这一点:

我已经修改了我的客户端以允许配置文件范围但没有任何运气,而且我得到了不同类型的响应和声明处理针对同一用户在 IS4 上使用相同的配置:

我的问题是,当我使用密码流程取回索赔时,是否需要在我的客户端中进行任何特殊设置,或者我是否需要修改配置文件服务以始终包含它们?我本可以想象,当您可以访问不同的范围并且他们已经发出声明时,您应该将它们取回,但我不确定我是否遗漏了一些基本的东西。

我客户的配置:

public static IEnumerable<Client> Get()
    {
        return new List<Client>
        {
            new Client
            {
                ClientId = "web",
                ClientName = "Web Client",
                AllowedGrantTypes = GrantTypes.Code,
                RequirePkce = true,
                RequireClientSecret = false,
                AllowedScopes = new List<string> { "openid", "profile", "myapi" },
                RedirectUris = new List<string> {
                    "http://<base-url>/auth-callback",
                    "http://<base-url>/silent-renew-callback",
                },
                PostLogoutRedirectUris = new List<string> {"http://<base-url>"},
                AllowedCorsOrigins = new List<string> {"http://<base-url>"},
                AllowAccessTokensViaBrowser = true,
                RequireConsent = false,
                AlwaysSendClientClaims = true,
                AlwaysIncludeUserClaimsInIdToken = true,
            },
            new Client
            {
                ClientId = "mobile",
                ClientName = "Mobile Client",
                ClientSecrets = { new Secret("t8Xa)_kM6apyz55#SUv[[Cp".Sha256()) },
                AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                AllowedScopes = new List<string> { "openid", "mobileapp", "myapi" },
                AccessTokenType = AccessTokenType.Jwt,
                AccessTokenLifetime = 3600,
                IdentityTokenLifetime = 3600,
                UpdateAccessTokenClaimsOnRefresh = false,
                SlidingRefreshTokenLifetime = 30,
                AllowOfflineAccess = true,
                RefreshTokenExpiration = TokenExpiration.Absolute,
                RefreshTokenUsage = TokenUsage.OneTimeOnly,
                AlwaysSendClientClaims = true,
                Enabled = true
            }
        };
    }
}

非常感谢任何提示。非常感谢!

更新:由于 ROPC 流在 oauth 2.1 (https://fusionauth.io/blog/2020/04/15/whats-new-in-oauth-2-1) 中被弃用,我决定将所有内容移动到代码流 + PKCE 机制。

密码授权是一个OAuth grant,是为了获得一个访问令牌。您看到的密码授予结果是一个访问令牌。访问令牌除了 ID(子声明)外不包含任何有关用户本身的信息。

但是Implicit grant你用的是OpenId Grant。您使用 oidc 客户端库并在客户端上使用 "openid", "profile" - AllowedScopes。你得到的结果是一个 id 令牌。此令牌向应用程序验证用户并包含用户信息。

阅读更多关于代币的信息here

这是一个很好的 post 其中 Diagrams of All The OpenID Connect Flows