2016-04-25 40 views
2

我在我的應用程序下面的代碼,說WebApp1:UseIdentityServerBearerTokenAuthentication如何驗證JWT令牌(本地模式)

app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions 
     { 

      Authority = "IdentityServerPath", 
      RequiredScopes = new[] { "write", "role", "all_claims" }, 
      ValidationMode = ValidationMode.Local, 
     }); 

來電/客戶端應用程序將JWT令牌WebApp1。 WebApp1如何知道JWT令牌有效? WebApp1是否需要知道JWT令牌的公鑰?如果沒有,WebApp1如何驗證JWT的簽名?請注意,我使用ValidationMode作爲本地,因此WebApp1將不會聯繫IdentityServer來驗證JWT令牌。

+0

你好,你的客戶使用隱式流? – Alegrowin

回答

3

對於「本地」選項,UseIdentityServerBearerTokenAuthentication使用發現文檔(https://openid.net/specs/openid-connect-discovery-1_0.html)動態下載驗證JWT所需的簽名材料。

「驗證端點」的另一種選擇使用任一自定義令牌驗證端點(https://identityserver.github.io/Documentation/docsv2/endpoints/accessTokenValidation.html),或者如果被配置的客戶機ID和祕密,則標準的OAuth2反思(https://tools.ietf.org/html/rfc7662)端點用於驗證該令牌(https://identityserver.github.io/Documentation/docsv2/endpoints/introspection.html )。

「both」的最後一個選項將基於呈現給Web API的傳入訪問令牌的一些啓發式動態地確定上述兩種方法中的哪一種。

+0

謝謝。我認爲我需要明確地進行驗證。我剛剛瞭解到驗證已經發生:UseIdentityServerBearerTokenAuthentication代碼本身。 –