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
api
directory in your terminal. - Run
composer install
- Copy
.env.example
file to.env
and 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-vue
directory - Run
npm install
- this takes a while - Copy
.env.example
to.env.development.local
- Fill out details:
VUE_APP_API_URL
should point to:YOURDOMAIN/api/v1/
(replace YOURDOMAIN with the domain you set up for the API) - Run
npm run serve
and open the given address (should look something like:http://localhost:808*
where * is number from 0 to 9) - Visit
Users list
in 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-vue
directory - Run
npm install
- this takes a while - Copy
.env.example
to.env.development.local
- Fill out details:
VUE_APP_API_URL
should point to:YOURDOMAIN/api/v1/
(replace YOURDOMAIN with the domain you set up for the API) - Run
npm run serve
and 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.com
with 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-vue
directory - Run
npm install
- this takes a while - Copy
.env.example
to.env.development.local
- Fill out details:
VUE_APP_API_URL
should point to:YOURDOMAIN/api/v1/
(replace YOURDOMAIN with the domain you set up for the API) - Run
npm run serve
and 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.com
with 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
api
directory - 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-vue
directory - Run
npm install
- this takes a while - Copy
.env.example
to.env.development.local
- Fill out details:
VUE_APP_API_URL
should point to:YOURDOMAIN/api/v1/
(replace YOURDOMAIN with the domain you set up for the API)VUE_APP_AUTH_URL
should point to:YOURDOMAIN/oauth/token
(replace YOURDOMAIN with the domain you set up for the API)VUE_APP_API_CLIENT_ID
should be set to databaseid
column from table:oauth_clients
wherepassword_client
is equal to1
VUE_APP_API_CLIENT_SECRET
should be set to databasesecret
column from table:oath_clients
wherepassword_client
is equal to 1- Run
npm run serve
and 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.com
with passwordpassword
- Users list should appear
- Click on users list and you should see users being listed.