2016-11-05 40 views
0

我正在嘗試使用Symfony 3.1和FOSRestBundle,FOSUserBundle和FOSOAuthServerBundle構建REST API。我設法按照https://gist.github.com/tjamps/11d617a4b318d65ca583的指南完成此操作。FOSOAuthServerBundle:無效的grant_type參數或參數丟失

我現在在認證過程中掙扎。當我使POST請求到服務器進行認證(爲localhost:8000 /的OAuth/V2 /令牌)與在請求體中JSON編碼的參數:

{ 
    "grant_type": "password", 
    "client_id": "1_myveryverysecretkey", 
    "client_secret": "myveryverymostsecretkey", 
    "username": "theuser", 
    "password": "thepassword" 
} 

附加HTTP頭有以下幾種:

Accept: application/json 
Cache-Control: no-store, private 
Connection: close 
Content-Type: */json 

根據指南的建議,db表oauth2_client中的客戶端具有「密碼」grant_type a:1:{i:0;s:8:"password";}

服務器接受請求,但我總是得到的迴應

{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"} 

任何建議什麼,我缺少什麼?謝謝!

+0

有沒有人可能有提示? – RalphP

回答

0

我有同樣的問題。看來fosOAuthBundle不接受json。如果您發送帶有表單字段的查詢,它將起作用。

0

這是因爲FOSRestBundle使用身體偵聽器將下劃線鍵轉換爲駱駝大小寫。因此,您的OAuth2服務器獲取的參數不是grant_type,而是grantType,它無法處理,因此它會給出該錯誤。

解決方法是在fos rest的主體偵聽器上使用自定義數組規範器。

相關問題