我有一个 Identity Server 4 的本地实例,我正在尝试遵循本指南 http://docs.identityserver.io/en/release/quickstarts/7_javascript_client.html创建一个 Javascript 客户端。这使用了oidc-客户端-js https://github.com/IdentityModel/oidc-client-js库,我正在使用登录弹出方法,因此我的登录事件处理程序如下所示:
signin(e) {
e.preventDefault();
this.oidcUserMgr.signinPopup({state:'some data'}).then(function(user) {
console.log("signed in", user.profile);
}).catch(function(err) {
console.log(err);
});
}
身份验证似乎工作正常 - 我被重定向到我的身份服务器,它接受客户端请求,验证我的登录并将我返回到客户端应用程序。然而,文档说user.profile
上面代码中的 object 应包含用户声明,但事实并非如此。这是use.profile
我回来了:
The sub
property 是刚刚经过身份验证的用户的正确 ID。但我的身份服务器还发布了声明以响应我的客户请求的其他范围(profile
and email
)所以我应该看到诸如name
, preferred_username
, email
ETC)。我可以在调试我的设备时观察到这些声明的发出IProfileService
IS4 中的实现。此外,如果我使用access_token
与用户对象一起返回以向本地运行的另一个 API(ASP.NET Web API)发出请求我确实在中看到了这些声明this.User.Claims
:
那么我怎样才能在我的 Javascript 代码中掌握这些声明呢?
这些用户声明可能会出现在 ID 令牌内。为了使这项工作正常进行,请检查您是否有AlwaysIncludeUserClaimsInIdToken = true
在您的 IDP 提供商的客户端配置中,例如
public static IEnumerable<Client> GetClients()
{
return new List<Client>()
{
new Client()
{
ClientName = "IDP Client",
ClientId = "client",
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.Hybrid,
RedirectUris = new List<string>()
{
"http://localhost:60811/signin-oidc"
},
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"myapi"
},
AlwaysIncludeUserClaimsInIdToken = true,
AllowOfflineAccess = true
},
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)