Code Monkey home page Code Monkey logo

tutorials-api-auth's Introduction

About

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

Setting up Laravel API

Base setup for our Laravel API is the same across all of the branches.

Requirements

https://laravel.com/docs/7.x#server-requirements

Steps

  • 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.

Master branch - Public API

Laravel

Requires no additional steps

VueJS

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.

Demo/Sanctum branch - Laravel sanctum protected

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.

Laravel

Requires no additional steps

VueJS

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 [email protected] with password password
  • Users list should appear
  • Click on users list and you should see users being listed.

Demo/Passport - Laravel passport protected

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.

Laravel

Requires no additional steps

VueJS

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 [email protected] with password password
  • Users list should appear
  • Click on users list and you should see users being listed.

Demo/Passport-oAuth - Laravel passport protected

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

Laravel

  • Enter api directory
  • Run php artisan passport:install

VueJS

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 database id column from table: oauth_clients where password_client is equal to 1
  • VUE_APP_API_CLIENT_SECRET should be set to database secret column from table: oath_clients where password_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 [email protected] with password password
  • Users list should appear
  • Click on users list and you should see users being listed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.