2016-09-30 76 views
1

我有一个支持身份验证的承载令牌的API。身份服务器客户机上的唯一标识符

有自定义帐户和外部登录。现在,当用户访问API时,我想访问用户的唯一标识符以将数据与他联系起来。

我首先想到了这个问题,但没有任何主题声明。那么这个问题不是正确的?或者我只是缺少一个配置?如果UniqueNameIdentifier是我应该使用的东西?

user.Claims.First(I => I.Type == ClaimTypes.NameIdentifier).Value; 

当我使用的是由具有一个外部提供商(脸谱)我可以看到的NameIdentifier包含一个标识身份验证的访问令牌,所以这是可靠的?

还有一个网站,这也是与此身份服务器进行身份验证。有主题返回,我可以看到它具有相同的值这个名称标识符。但为什么有一个偏移量,为什么不在api配置中返回的值作为主题?

什么是推荐的方式

我在消费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" 
       } 
      }; 

回答

1

使用的主题要求。它用于唯一标识用户,这就是jwt声明类型的用途。

+0

我做了,但现在我得到了一些问题,形成时不时的主题正在改变,当我与外部provoder验证看到https://stackoverflow.com/questions/39895086/identityserver-with-facebookprovider-use-subject-如,用户标识 –