2016-09-30 44 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-如,用戶標識 –

相關問題