IdentityServer 客户端上的唯一标识符
Unique Identitfier on IdentityServer Client
我有一个 api 支持不记名令牌进行身份验证。
有自定义帐户和外部登录。现在,当用户访问 api 我想访问用户的唯一标识符以将数据与他关联。
我首先想到了主题,但是没有主题声明。那么这个主题不对吗?还是我只是缺少配置?如果 UniqueNameIdentifier 是我应该使用的东西?
user.Claims.First(I => I.Type == ClaimTypes.NameIdentifier).Value;
当我使用由外部提供商 (facebook) 验证创建的访问令牌时,我可以看到 NameIdentifier 包含一个 ID,这可靠吗?
还有一个网站也使用此身份服务器进行身份验证。那里返回了主题,我可以看到它具有与此名称标识符相同的值。但是为什么会有偏移量,为什么在 api 配置中没有作为 subjec 返回的值?
推荐的方式是什么
我在消费 api 中的配置是:
string identServer = ConfigurationManager.AppSettings["pluto:identity:server:url"];
app.UseIdentityServerBearerTokenAuthentication(new IdentityServer3.AccessTokenValidation.IdentityServerBearerTokenAuthenticationOptions()
{
Authority = identServer ,
});
并且身份服务器中的配置是:
return new Client
{
Enabled = true,
ClientId = "pluto",
ClientName = "Pluto Site",
ClientSecrets = new List<Secret>
{
new Secret("foo".Sha256())
},
Flow = Flows.ResourceOwner,
AllowedScopes = new List<string>
{
Constants.StandardScopes.OpenId,
"read"
}
};
使用主题声明。它用于唯一标识用户,这就是 jwt 声明类型的用途。
我有一个 api 支持不记名令牌进行身份验证。
有自定义帐户和外部登录。现在,当用户访问 api 我想访问用户的唯一标识符以将数据与他关联。
我首先想到了主题,但是没有主题声明。那么这个主题不对吗?还是我只是缺少配置?如果 UniqueNameIdentifier 是我应该使用的东西?
user.Claims.First(I => I.Type == ClaimTypes.NameIdentifier).Value;
当我使用由外部提供商 (facebook) 验证创建的访问令牌时,我可以看到 NameIdentifier 包含一个 ID,这可靠吗?
还有一个网站也使用此身份服务器进行身份验证。那里返回了主题,我可以看到它具有与此名称标识符相同的值。但是为什么会有偏移量,为什么在 api 配置中没有作为 subjec 返回的值?
推荐的方式是什么
我在消费 api 中的配置是:
string identServer = ConfigurationManager.AppSettings["pluto:identity:server:url"];
app.UseIdentityServerBearerTokenAuthentication(new IdentityServer3.AccessTokenValidation.IdentityServerBearerTokenAuthenticationOptions()
{
Authority = identServer ,
});
并且身份服务器中的配置是:
return new Client
{
Enabled = true,
ClientId = "pluto",
ClientName = "Pluto Site",
ClientSecrets = new List<Secret>
{
new Secret("foo".Sha256())
},
Flow = Flows.ResourceOwner,
AllowedScopes = new List<string>
{
Constants.StandardScopes.OpenId,
"read"
}
};
使用主题声明。它用于唯一标识用户,这就是 jwt 声明类型的用途。