2016-09-16 74 views
1

我已經設置了一個在IIS中運行的IdentityServer3實例。IdentityServer3 PostMan invalid_client

 var validators = new List<Registration<ISecretValidator>> 
     { 
      new Registration<ISecretValidator, HashedSharedSecretValidator>(), 
      new Registration<ISecretValidator, X509CertificateThumbprintSecretValidator>() 
     }; 

     // .Register() is an extension method that setups that setups the 
     // IdentityServerServiceFactory 
     var factory = new EntityFrameworkServiceOptions() 
        .Register() 
        .UseInMemoryUsers(Users.Get()); 
     factory.SecretValidators = validators; 

     app.Map($"/{IdentityServer.Path}", server => 
     { 
      server.UseIdentityServer(new IdentityServerOptions() 
      { 
       RequireSsl = false, 
       SiteName = siteName, 
       SigningCertificate = Certificate.Load(), 
       Factory = factory, 

       // Currently does nothing. There are no plugins. 
       PluginConfiguration = ConfigurePlugins, 
       AuthenticationOptions = new AuthenticationOptions() 
       { 
        EnablePostSignOutAutoRedirect = true, 

        // Currently does nothing. There are no IdentityProviders setup 
        IdentityProviders = ConfigureIdentityProviders 
       } 
      }); 
     }); 

我已經在客戶端憑證流程的EF數據庫中設置了一個客戶端。因此,在Client表中有一個客戶端,我已向客戶端訪問ClientScopes表中的範圍,並且我已在ClientSecrets表中爲客戶端提供了一個祕密。

存儲在數據庫中的相關值(未列出的所有值都是IdentityServer3默認):

ClientId = 'client' 
Flow = 'ClientCredentials [3]' 
ClientScope = 'api' 
ClientSecret = 'secret'.Sha256() 

我想從郵差一個新的令牌:enter image description here

enter image description here

IdentityServer正在測試服務器上運行,這就是爲什麼我沒有選擇「本地請求訪問令牌」的原因。

當我點擊「請求令牌」我收到以下錯誤記錄:

2016-09-16 16:18:28.470 -05:00 [Debug] Start client validation 
2016-09-16 16:18:28.470 -05:00 [Debug] Start parsing Basic Authentication secret 
2016-09-16 16:18:28.470 -05:00 [Debug] Parser found secret: "BasicAuthenticationSecretParser" 
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Secret id found: "client" 
2016-09-16 16:18:28.470 -05:00 [Debug] No matching hashed secret found. 
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Secret validators could not validate secret 
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Client validation failed. 
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] End token request 
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Returning error: invalid_client 

我真的不知道爲什麼驗證無法驗證的祕密。它被保存在數據庫中,Sha256和IdentityServer可以解析和驗證Sha256。

UPDATE: 我得到它的工作做從郵遞員POST,並填寫相應的X WWW的形式,進行了urlencoded領域,但我還沒有想出如何得到它的使用授權工作標籤和Postman的「獲取新訪問令牌」功能。不能用於從IdentityServer3獲取令牌嗎?

回答

0

我有它的工作,但不使用郵遞員的「獲取新訪問令牌」功能。我無法弄清楚爲什麼這不起作用:p我只是發佈到令牌URL,它給了我一個訪問令牌,然後我可以在隨後的調用中使用它。

POST:https://開頭{{服務器}} /連接/令牌 CLIENT_ID: client_secret: grant_type:client_credentials 範圍:

然後用它在你的服務器調用以下內容添加到你的頭:

授權:承載[的access_token]

2

的OAuth2用戶的支持令牌建成郵差工作正常。您可以使用客戶端。客戶端憑證和授權代碼授予類型都可以正常工作 - 如果您按照以下所示設置授權代碼類型,您甚至會得到一個允許您輸入用戶名和密碼的彈出窗口。下面是我使用的授權碼流客戶端進入:

new Client 
{ 
    ClientId = "postmantestclient", 
    ClientName = "Postman http test client", 
    Flow = Flows.AuthorizationCode, 
    AllowAccessToAllScopes = true, 
    IdentityTokenLifetime = 60 * 60 * 24, 
    AccessTokenLifetime = 60 * 60 * 24, 
    RequireConsent = false, 
    ClientSecrets = new List<Secret> 
    { 
     new Secret("PostmanSecret".Sha256()) 
    }, 
    RedirectUris = new List<string>() 
    { 
     "https://www.getpostman.com/oauth2/callback" 
    } 
} 

,這裏是我設置從郵差

Get New Access Token Popup in Postman Desktop

不是對話框中的URL請求的方式。系統不是很寬容,如果你的網址錯誤,當你提出請求時你可能會看到一個完全錯誤的CORS錯誤。

+0

我將回調URL添加到客戶端的重定向uris。我將我的令牌名稱更新爲「承載者」。我將Auth網址更改爲授權終點。 (我的授權類型仍然是Client Credentials)。我在本地檢查了請求訪問令牌複選框,並且仍然使用此方法得到「invalid_client」...客戶端是否必須使用「授權碼」流設置? –

+0

我已經使用客戶端證書和資源代碼來完成它的工作。唯一的區別是資源代碼郵差會彈出一個登錄對話框。這對於我工作的開發很方便,因爲大量REST服務調用需要與特定用戶關聯。 – GlennSills