Demo-project with Laravel and Vue.js to show four ways of authentication:
- Public (so no Auth)
- Laravel Sanctum
- Laravel Passport
- Laravel Passport with oAuth
Base setup for our Laravel API is the same across all of the branches.
https://laravel.com/docs/7.x#server-requirements
- Enter
apidirectory in your terminal. - Run
composer install - Copy
.env.examplefile to.envand fill out your details. - Run
php artisan key:generate - Run
php artisan migrate:fresh --seed - Configure domain to serve your application via chosen server provider (WAMP, MAMP, LAMP, Valet, homestead, VPS or something different)
That is it - your base API should be ready to go. You can confirm by visiting the configured domain and seeing a login page. This is your administrator login.
Requires no additional steps
Important: Make sure you have nodejs and npm installed (yarn will work too but replace our commands).
To set up public API test you'll need to follow these steps:
- Enter
client-vuedirectory - Run
npm install- this takes a while - Copy
.env.exampleto.env.development.local - Fill out details:
VUE_APP_API_URLshould point to:YOURDOMAIN/api/v1/(replace YOURDOMAIN with the domain you set up for the API) - Run
npm run serveand open the given address (should look something like:http://localhost:808*where * is number from 0 to 9) - Visit
Users listin the loaded page and you should see the data.
This demo uses https://laravel.com/docs/7.x/sanctum#introduction to protect the API from unauthorised access. In this example we are using JWT tokens.
Requires no additional steps
Important: Make sure you have nodejs and npm installed (yarn will work too but replace our commands).
To set up sanctum API test you'll need to follow these steps:
- Enter
client-vuedirectory - Run
npm install- this takes a while - Copy
.env.exampleto.env.development.local - Fill out details:
VUE_APP_API_URLshould point to:YOURDOMAIN/api/v1/(replace YOURDOMAIN with the domain you set up for the API) - Run
npm run serveand open the given address (should look something like:http://localhost:808*where * is number from 0 to 9) - You should see Home and Login navigation buttons on the page.
- Click on login and login using these details
admin@admin.comwith passwordpassword - Users list should appear
- Click on users list and you should see users being listed.
This example uses https://laravel.com/docs/7.x/passport#introduction to protect the API from unauthorised access. In this example we are using JWT tokens.
Requires no additional steps
Important: Make sure you have nodejs and npm installed (yarn will work too but replace our commands).
To set up passport API test you'll need to follow these steps:
- Enter
client-vuedirectory - Run
npm install- this takes a while - Copy
.env.exampleto.env.development.local - Fill out details:
VUE_APP_API_URLshould point to:YOURDOMAIN/api/v1/(replace YOURDOMAIN with the domain you set up for the API) - Run
npm run serveand open the given address (should look something like:http://localhost:808*where * is number from 0 to 9) - You should see Home and Login navigation buttons on the page.
- Click on login and login using these details
admin@admin.comwith passwordpassword - Users list should appear
- Click on users list and you should see users being listed.
This example uses https://laravel.com/docs/7.x/passport#introduction to protect the API from unauthorised access. In this example we are using oAuth protection
- Enter
apidirectory - Run
php artisan passport:install
Important: Make sure you have nodejs and npm installed (yarn will work too but replace our commands).
To set up public API test you'll need to follow these steps:
- Enter
client-vuedirectory - Run
npm install- this takes a while - Copy
.env.exampleto.env.development.local - Fill out details:
VUE_APP_API_URLshould point to:YOURDOMAIN/api/v1/(replace YOURDOMAIN with the domain you set up for the API)VUE_APP_AUTH_URLshould point to:YOURDOMAIN/oauth/token(replace YOURDOMAIN with the domain you set up for the API)VUE_APP_API_CLIENT_IDshould be set to databaseidcolumn from table:oauth_clientswherepassword_clientis equal to1VUE_APP_API_CLIENT_SECRETshould be set to databasesecretcolumn from table:oath_clientswherepassword_clientis equal to 1- Run
npm run serveand open the given address (should look something like:http://localhost:808*where * is number from 0 to 9) - You should see Home and Login navigation buttons on the page.
- Click on login and login using these details
admin@admin.comwith passwordpassword - Users list should appear
- Click on users list and you should see users being listed.