![](/img/trans.png)
[英]Laravel Passport - Invalid credentials using grant_type is passowrd
[英]How to enable client credentials grant type in laravel passport
我正在嘗試使用laravel 5.3開發使用令牌的靜態API進行身份驗證。 我還添加了laravel護照,我認為這將幫助我更快地構建api。 我想通過api提供的資源是所有用戶共有的,而用戶沒有特定的資源。 所以我認為應該使用授權類型:客戶端憑據。 我在laravel文檔中找不到有關此授予類型的任何幫助
https://github.com/laravel/passport/pull/34/files此鏈接顯示客戶端憑據授予類型已添加到laravel護照。 但是當我嘗試授予類型作為客戶端憑據時
$http = new \GuzzleHttp\Client;
$response = $http->post('http://site.dev/oauth/token', [
'form_params' => [
'grant_type' => 'client_credentials',
'client_id' => config('api.client_id'),
'client_secret' => config('api.client_secret'),
'redirect_uri' => config('api.redirect_uri'),
],
]);
它給出了使用的授予類型錯誤。
我使用的是客戶端憑據方法,因為它是一台機器到機器的調用。 我收到類似{“ error”:“未經身份驗證”的錯誤。 }`使用郵遞員時。 我使用了訪問類型和授權標頭,但遇到了相同的錯誤。 然后我用谷歌搜索並嘗試了下面鏈接中解釋的方法。 有效。 :) :) http://filljoyner.com/2017/03/01/how-to-use-client-credentials-grant-tokens-for-your-api-authorization-with-laravel-5-4s-passport/
當您安裝Laravel Passport時,默認情況下在oath_clients表中安裝了一個密碼授予,但password_client列應為1而不是0。
然后,您將一些 form_data發送到/oauth/token
url並獲得access_token
作為回報。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.