2017-09-24 416 views
1

我一直在試圖讓IdentityServer4的最簡單的例子,以請求落後於純代碼的訪問工作。使用客戶端請求,但沒有做一個用戶登錄的時候,當我可以得到一個訪問令牌..IdentityServer4 unsupported_grant_type錯誤

var discos = new DiscoveryClient(authority); 
     var disco = await discos.GetAsync(); 

     if (disco.IsError) 
     { 
      Console.WriteLine(disco.Error); 
      return null; 
     } 

     var tokenClient = new TokenClient(disco.TokenEndpoint, "ro.client", "secret"); 

     var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync("username", "password", "api1"); 

這使得使用用戶信息請求的客戶端。 我得到一個永久的unsupported_grant_type ..

服務器有它設置爲:

new Client 
      { 
       ClientId = "ro.client", 
       AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, 

       ClientSecrets = 
       { 
        new Secret("secret".Sha256()) 
       }, 
       AllowedScopes = { "api1" } 
      } 

任何人都可以請鑑定一下林mising。用戶可以登錄使用前端快速啓動界面,該軟件提供,這是內置的功能。爲什麼不會,如果該公司是有效發揮作用。

+1

你使用內存的用戶? –

+1

檢查日誌... – leastprivilege

回答

1

你ClientSecrets配置爲「祕密」,而不是字面上的「祕密」的SHA256。

更新您的tokenClient傳遞的SHA256「祕密」,而不是字面上的「祕密」

var tokenClient = new TokenClient(disco.TokenEndpoint, "ro.client", "secret".Sha256());