angular - 身份服务器检索用户详细信息
问题描述
我一直在尝试按照本教程使用我的 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,它还将调用用户信息端点以获取它已被授权访问的任何额外身份数据。
如何授权用户信息端点访问我希望它访问的数据?
解决方案
您需要配置将返回哪些用户数据,我没有配置任何!
确保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")
}
}
};
}
然后,声明将出现在客户端的配置文件属性中。
推荐阅读
- css - 如何将多个 css 文件和 javascript 文件编译成一个文件?
- go - 当你从一个频道读取并且你正在推送到另一个频道时,你如何编写一个不会挂起的函数
- android - androidx.appcompat.view.menu.ActionMenuItemView 无法转换为 android.view.MenuItem
- java - Java 内存堆调优
- marklogic - Marklogic ml-gradle 不清除数据库
- reactjs - 嵌套 Emotion 10 类级联
- android - StaggeredGridLayout,每行动态对象数,换行
- opengl - 如何确定调用 glTexImage3D() 的数据长度(以字节为单位)?
- html - 创建从条形图到相同条形图但具有不同列的转换时出错
- c++ - 为什么 std::bitset<5>{}[0] 不是 constexpr?