Laravel 5.4 Passport Eklentisi
08-07-2017Password Grant Token
Kullanıcılara API aracılığı ile giriş yapılmasını sağlar.
php artisan password:client --password
komutu çağrıldığı zaman oauth_clients tablosuna aşağıdaki gibi bir satır eklenir:
id | user_id | name | secret | redirect | personel_access_client | password_client | revoked | created_at | updated_at |
1 | null | mobil | PsgprbVQ12UPmjLhxEde23iChJA9CglneuhMpRB8 | localhost | 0 | 1 | 0 | 2017-07-08 11:34:53 | 2017-07-08 11:34:53 |
Bu işlemden sonra kullanıcı API aracılığı ile giriş yapmak istediği zaman önce access_token ve refresh_token bilgilerini aşağıdaki gibi sunucuya istek gönderek alması gerekmektedir:
$http = new GuzzleHttp\Client; $response = $http->post('http://your-app.com/oauth/token', [ 'form_params' => [ 'grant_type' => 'password', 'client_id' => 'client-id', 'client_secret' => 'client-secret', 'username' => 'taylor@laravel.com', 'password' => 'my-password', 'scope' => '', ], ]); return json_decode((string) $response->getBody(), true);
Dönen örnek sonuç:
{ "token_type": "Bearer", "expires_in": 1296000, "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjUwZmQ3NmI0ZGVjYmY1YjBlYWYzNWE5MWNjMWE3NTdjYWJjMzMzNjEwYTM3ZWZiYmMyNTgxNTQyMGU3YzI4OWVkMDM0ODMyM2FkNGE3MTk0In0.eyJhdWQiOiI3IiwianRpIjoiNTBmZDc2YjRkZWNiZjViMGVhZjM1YTkxY2MxYTc1N2NhYmMzMzM2MTBhMzdlZmJiYzI1ODE1NDIwZTdjMjg5ZWQwMzQ4MzIzYWQ0YTcxOTQiLCJpYXQiOjE0OTk1MTM3ODEsIm5iZiI6MTQ5OTUxMzc4MSwiZXhwIjoxNTAwODA5NzgxLCJzdWIiOiIyIiwic2NvcGVzIjpbXX0.v3Vk6pd-tri4gBfWYN56xaDeBAJnJUYqwHFetdSeRNcoM9-F1jcjrbNdcaqo5cSyDlt9uDfeUu3VdYyyKXNs9FV0er90AF4VGiQwjaU-YpYaFyD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ZuAB/aaNfkTzj5jIpg5nlX1Putb8Fy527UCtRsQb8nO6p0ppukTq1oh3gVTJDzyTD0hcXLGh3K9PQgzaeobRxn6VajgHRewCFVt3Q6LSiFlK8DSpkjJpndpSKfAMmBdYNXGf6cHEiU+b6J8u/tMiJkPUVBe21rvF9+rDdb8ZOM=" }
Not: 'scope' => '*'
şeklinde kullanıldığı zaman tüm scope'lara erişim izni verilmiş olur.