get*_*ode 5 javascript asp.net openid-connect identityserver4 oidc-client-js
我有Identity Server 4的本地实例,我正在尝试按照本指南创建Javascript客户端。这使用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);
});
}
Run Code Online (Sandbox Code Playgroud)
身份验证似乎可以正常工作-我已重定向到接受客户端请求,对我的登录进行身份验证并将我返回到客户端应用程序的Identity Server。但是,文档说user.profile上述代码中的对象应包含用户声明,但没有。这是use.profile我得到的:
该sub属性是刚刚通过身份验证的用户的正确ID。但我的身份服务器也发出响应其他领域我的客户要求(索赔profile和email),所以我应该看到的索赔,如name,preferred_username,email等)。我可以观察到IProfileService在IS4中调试我的实现时发出的这些声明。此外,如果我使用access_token带有用户对象的return来向本地运行的另一个API(ASP.NET Web API)发出请求,则可以在this.User.Claims以下位置看到这些声明:
那么如何在我的Javascript代码中掌握这些主张呢?
这些用户声明可能在ID令牌中。要使其正常工作,请检查您是否已进入AlwaysIncludeUserClaimsInIdToken = trueIDP提供商的客户端配置,例如
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
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1587 次 |
| 最近记录: |