我有一个Identity Server 4的本地实例,我正在尝试关注this guide来创建一个Javascript客户端。这使用了oidc-client-js库,我正在使用signin弹出方法,所以我的登录事件处理程序如下所示:
HKWorkoutSession
身份验证似乎工作正常 - 我被重定向到我的Identity Server,它接受客户端请求,验证我的登录并将我返回到客户端应用程序。但是,文档说上面代码中的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
:
use.profile
属性是刚刚进行身份验证的用户的正确ID。但我的Identity Server也发出了声明,以响应我的客户请求的其他范围(sub
和profile
),因此我应该看到email
,name
,{ {1}}等等。我可以观察在IS4中调试preferred_username
实现时发出的这些声明。此外,如果我使用随用户对象返回的email
向本地运行的另一个API(ASP.NET Web API)发出请求,我会在IProfileService
中看到这些声明:
那么如何在我的Javascript代码中掌握这些声明呢?
答案 0 :(得分:4)
这些用户声明可能会进入ID令牌。要做到这一点,请检查您的IDP提供商的客户端配置中是否有AlwaysIncludeUserClaimsInIdToken = true
,例如
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
},