API Passport
Client Password Grant Client, . Passport.
, :
php artisan passport:client --password
, auth: api.
, /oauth/token route (, , PHP, , Java):
$http = new GuzzleHttp\Client;
$response = $http->post('http://your-app.com/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => '<client id returned from the artisan command above>',
' client_secret' => '<secret returned from artisan command above>',
'username' => 'taylor@laravel.com',
'password' => 'my-password',
'scope' => '',
],
]);
return json_decode((string) $response->getBody(), true);
, client_secret client_id, , , username password .
, access_token refresh_token . access_token - , auth:api. api, Authorization: Bearer <your accessToken> Accept: application/json
, "" :
$response = $client->request('GET', '/api/test', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '. <accessToken from /oauth/token call>,
],
]);
, JSON .
/api/test ?
auth:api. , , , .
, .