2016-08-30 101 views
0

以下代碼無效。授予類型是「client_credentials」。它返回狀態爲-1的空響應。 API是好的。這兩個請求都可以在郵遞員上正常工作Restangular - 不支持Client_credentials授權類型?

function authentication(user) { 
      return Restangular 
       .all('token') 
       .post('grant_type=client_credentials&client_id=' + APPLICATION.clientId + '&client_secret=' + 'XYZ', 
       undefined, { 'Content-Type': 'application/x-www-form-urlencoded' }); 
     } 

以下代碼與「password」授權類型完美配合。

function authentication(user) { 
      return Restangular 
       .all('token') 
       .post('grant_type=password&username=' + user.username + '&password=' + user.password + '&client_id=' + APPLICATION.clientId, 
       undefined, { 'Content-Type': 'application/x-www-form-urlencoded' }); 
     } 

出了什麼問題?

回答

0

看起來您正在使用相同的client_id來進行這些調用。第二個工作示例顯示客戶端是所謂的「公共客戶端」,因爲它無需身份驗證即可識別自己。您的第一個示例需要一個機密的客戶端,因爲客戶端需要在client_credentials流程中對自身進行身份驗證。這兩者不能混用,因此您的客戶端在授權服務器上註冊爲公共客戶端,因此根據定義,它不能使用客戶端憑據授權類型。

+0

這些只是例子。這兩項要求對郵遞員都適用。 – thiago