【问题标题】:Identity server retrieving user details身份服务器检索用户详细信息
【发布时间】:2023-04-10 00:29:01
【问题描述】:

我一直在尝试通过关注this tutorial 来使用我的 Angular 应用程序实现身份服务器。到目前为止,我发现它真的很有帮助。

我想获取用户名和一些自定义详细信息,但我不知道该怎么做。

在部分

export function getClientSettings(): UserManagerSettings {
    return {
        authority: 'http://localhost:5555/',
        client_id: 'angular_spa',
        redirect_uri: 'http://localhost:4200/auth-callback',
        post_logout_redirect_uri: 'http://localhost:4200/',
        response_type:"id_token token",
        scope:"openid profile api1",
        filterProtocolClaims: true,
        loadUserInfo: true
    };
}

我确定我设置了loadUserInfo: true。但是当我查看返回对象的内容时,我看不到任何用户信息。

我需要在服务器上做些什么来返回用户名等吗?我目前正在使用 TestUser 类,但我希望在客户端的 user.profile 中看到用户名。在服务器上,我的用户设置为

new TestUser {
    SubjectId = "5BE86359-073C-434B-AD2D-A3932222DABE",
    Username = "scott",
    Password = "password"
}

如上所示,我可以看到SubjectId(虽然我觉得它映射到 sub 而不是 sid 很奇怪)

我理解本教程的方式是,一旦成功登录,oicd-client 将使用检索到的令牌再次调用服务器,以在您设置 loadUserInfo: true 时获取用户详细信息

为什么我看不到详细信息?

编辑:

再次浏览教程,我注意到了这一行:

如果 loadUserInfo 设置为 true,它还将调用用户信息端点以获取已被授权访问的任何额外身份数据。

如何授权用户信息端点访问我希望它访问的数据?

【问题讨论】:

  • 您可以在客户端配置中将 AlwaysIncludeClaimsInIdToken 设置为 true ,然后您就无需担心用户信息端点。

标签: angular identityserver4


【解决方案1】:

你需要配置返回什么用户数据,我没有配置!

Startup.cs 中确保您拥有以下信息:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddIdentityServer()
                ...
                .AddTestUsers(Users.Get())
                ...
    }

然后将claims 添加到您的用户

public static List<TestUser> Get()
    {
        return new List<TestUser> {
            new TestUser {
                SubjectId = "5BE86359-073C-434B-AD2D-A3932222DABE",
                Username = "scott",
                Password = "password",
                Claims = new List<Claim>
                {
                    new Claim("name", "scott"),
                    new Claim("website", "https://scott.com")
                }
            }
        };
    }

然后声明将出现在客户端的配置文件属性中。

【讨论】:

    猜你喜欢
    • 2011-03-06
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2017-07-16
    • 2011-05-30
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    相关资源
    最近更新 更多