1

我有一个通过toAngular 9连接的 Web 应用程序和一个使用流的 API。当我获得经过身份验证的用户时,我可以看到我想要的网站的几个声明,例如电子邮件地址、用户名或角色。 oidc-clientIdentity Server 4Implicit在此处输入图像描述

我现在正在尝试使用密码流做同样的事情,我只得到了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
            }
        };
    }
}

任何提示都受到高度赞赏。非常感谢!

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

4

1 回答 1

1

Password grant is an OAuth grant and is to obtain an access token. And what you see as a result of password grant is an access token. access token does not contain any information about the user itself besides their ID (sub claim).

But Implicit grant you use is OpenId Grant. You use oidc client lib and use "openid", "profile" on client - AllowedScopes. What you get in result in an id token. This token authenticates the user to the application and contains user info.

Read more about tokens here.

And this is a very good post which Diagrams of All The OpenID Connect Flows

于 2020-07-28T20:45:26.593 回答