Laravel护照API Unsupported_grant_type错误

时间:2019-03-28 09:04:46

标签: laravel oauth laravel-passport

我在laravel中成功安装了护照api,我可以获取access_token  使用诸如

之类的请求令牌
   Route::get('/redirect', function () {
  $query = http_build_query([
      'client_id' => '1',
      'redirect_uri' => 'http://example.com/callback',
      'response_type' => 'code',
      'scope' => '',
  ]);

     return redirect('http://localhost:8000/oauth/authorize?'.$query);
  });

但是当我使用用户名和密码使用密码授予令牌created by php artisan passport:client --password时, 我得到了unsupported_grant_type

我的要求是

   $http = new GuzzleHttp\Client;
    $response = $http->post('http://localhost:8000/oauth/token', [
       'form_params' => [
        'grant_type' => 'password',
        'client_id' => '3',
        'client_secret' => 'sqgaA8HOBUZBBZwWnl4xhyDE7LWyhAhlG5BZa199',
        'username' => 'myusername',
        'password' => 'mypassword',
        'scope' => '',
        ],
      ]);

     return json_decode((string) $response->getBody(), true);

我收到这样的错误;

 {
 "error": "unsupported_grant_type",
 "message": "The authorization grant type is not supported by the authorization server.",
 "hint": "Check the `grant_type` parameter"
  }

我的oauth_clients表是

  id      => 3
  user_id => 1
  name    => Laravel Password Grant Client
  secret  => sqgaA8HOBUZBBZwWnl4xhyDE7LWyhAhlG5BZa199
  redirect => http://localhost
  personal_access_client => 0
  password_client => 1
  revoked => 0
  created_at => 2019-03-27 15:46:10
  updated_at => 2019-03-27 15:46:10

0 个答案:

没有答案