This package helps you authenticate users on a Laravel API based on JWT tokens generated from Laravel OAuth2.
✔️ I`m building an API with Laravel.
✔️ Composer is need to run the command in Laravel. https://getcomposer.org/
✔️ I use Laravel Passport for authentication.
✔️ The frontend is a separated project: https://github.com/dongvuduc/the-office
✔️ The frontend users authenticate directly on Laravel OAuth2 to obtain a JWT token.
✔️ The frontend keep the JWT token from Server.
✔️ The frontend make requests to the Laravel API, with that token.
Config Database in .env
Require the package
composer install
Create Database
php artisan migrate php artisan db:seed
Run with port 8000 (Local Server 8000 - Frontend 8080)
php artisan serve --port 8000
Create new Client for OAuth2 (Optional)
php artisan passport:client
Username: admin@admin.com Password: 12345678 Username: office@office.com Password: 12345678
CLIENT ID AND SECRET
Developers may use their client ID and secret to request an authorization code and access token from your application. First, the consuming application should make a redirect request to your application's like so:
GET http://SERVER_URL/oauth/authorize { 'client_id' => CLIENT_ID, 'redirect_uri' => APP_URL_CALLBACK, 'response_type' => 'code', 'scope' => 'import' }
If the user approves the authorization request, they will be redirected back to the consuming application. The request should include the authorization code that was issued by your application when the user approved the authorization request:
POST http://SERVER_URL/oauth/token { 'grant_type' => 'authorization_code', 'client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'redirect_uri' => APP_URL_CALLBACK, 'code' => AUTHORIZATION_CODE_FROM_SERVER, }
GET http://SERVER_URL/api/user HEADER: - Accept: application/json - Authorization: Bearer access_tokens
POST http://SERVER_URL/api/import HEADER: - Accept: application/json - Authorization: Bearer access_tokens { import_file: FILE_EXCEL_OR_CSV }
php artisan test