Skip to content

zacscoding/springboot-vuejs-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring boot + Vue.js auth sample

this is demo project for spring boot + vue.js with maven multi module.

  • backend : spring boot with OAuth2 server
  • frontend : vuejs with client app

Project structure

app@app:~/springboot-vuejs-auth$ tree ./ -L 2
./
├── backend         -> Server code
│   ├── pom.xml
│   ├── src
├── frontend        -> Vue.js code
│   ├── src
│   ├── pom.xml     
├── lombok.config
├── pom.xml         -> Maven parent pom

Getting access token from API(backend) by using POST MAN

http://localhost:3000/api/oauth/token

Authorization
- type : Basic Auth
- Username : myApp
- Password : pass

Body
x-www-form-urlencoded
username : user@email.com
password : user
grant_type : password

Api

Request Response
/api/home (with no token) Hello Anonymous!
/api/home (with token) Hello {email}!
/api/me (with no token) 401 error
/api/me (with token) {"email" : "user@email.com", "roles" : ["USER"]}

Getting started

  1. build frontend & running backend
$ git clone https://github.com/zacscoding/springboot-vuejs-auth.git
$ cd springboot-vuejs-auth
$ mvn clean install
$ java -jar backend/target/backend-1.0-SNAPSHOT.jar
OR
$ mvn --projects backend spring-boot:run

and then connect to http://localhost:3000/

  1. running respectively

backend with spring boot

$ cd backend
$ mvn spring-boot:run

frontend with webpack-dev-server

$ cd frontend
$ npm start

and then connect to http://localhost:8080/

Demos

  • home (with no sign in)

home_with_no_sign_in

  • home (with sign in)

home_with_sign_in

  • me (with sign in)

me with sign in

  • me (with no sign in)

=> then redirect to "/login?returnPath=me"

References