Package Data | |
---|---|
Maintainer Username: | cuonggt |
Maintainer Contact: | thaicuong.giang@gmail.com (Giang Thai Cuong) |
Package Create Date: | 2017-05-15 |
Package Last Update: | 2018-04-16 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-04-15 15:14:09 |
Package Statistics | |
---|---|
Total Downloads: | 781 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Extends default Laravel token guard to retrieve users from cookies and consume your own API from your JavaScript application.
To get started, you should add the gtk/laravel-token-guard Composer dependency to your project:
composer require gtk/laravel-token-guard
Once Laravel Token Guard is installed, you should register the Gtk\LaravelTokenGuard\ServiceProvider
service provider. Typically, this will be done automatically via Laravel's automatic service provider registration.
Typically, if you want to consume your API from your JavaScript application, you would need to manually send an access token to the application and pass it with each request to your application. However, Laravel Token Guard includes a middleware that can handle this for you like the way Laravel Passport do. All you need to do is add the CreateFreshApiToken
middleware to your web middleware group:
'web' => [
// Other middleware...
\Gtk\LaravelTokenGuard\CreateFreshApiToken::class,
],
This middleware will attach a api_token
cookie to your outgoing responses. This cookie contains a token will use to authenticate API requests from your JavaScript application like the default Laravel Token Guard. Now, you may make requests to your application's API without explicitly passing an access token:
axios.get('/api/user')
.then(response => {
console.log(response.data);
});
Laravel Token Guard is open-sourced software licensed under the MIT license.