Skip to content

little-pinecone/jwt-spring-boot-angular-scaffolding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwt-spring-boot-angular-scaffolding

keep growing logo

This project is a multi-module application, using Spring Boot for the backend and Angular for the frontend. The project can be built into a single jar file using Maven. You can also run the modules separately during development.

The backend and frontend are secured with JSON Web Token.

To learn how to set up a project like this one, check out the following posts:

Getting Started

To clone the repository, run in the command line:

$ git clone https://github.com/little-pinecone/jwt-spring-boot-angular-scaffolding.git

You can build the application with:

$ mvn clean install

Sign up request

You need to create a test user:

sign up request screenshot

  • path: http://localhost:8080/api/users

  • body:

{
    "userCredentials": {
        "username": "user",
        "password": "test"
    }
}

Add CSRF token to requests from Postman

  • Copy this code to the Tests tab for the mutable requests:
var xsrfCookie = postman.getResponseCookie("XSRF-TOKEN");
pm.globals.set('csrftoken', xsrfCookie.value);

add csrf to postman screenshot

  • Add the X-XSRF-TOKEN header that will use the {{csrftoken}} variable:

add csrf to postman screenshot

Overview and technical features

  • The project currently serves a login page and hard-coded pastry data returned from the API.
  • It allows registering new users, handles login requests.
  • It serves data from the API to authenticated and authorized users.
  • The user experience is enhanced thanks to the AuthGuard implementation.

Running tests

Run all backend tests with the following command in the root directory:

$ mvn test

Run all frontend tests with the following command in the frontend/src/main/angular directory:

$ ng test

Running in production

Set the target url in frontend/src/main/angular/src/proxy.conf.json to the path for the right environment. Add the "changeOrigin": true option if your backend is not running on localhost (Angular proxy documentation).

Override the default TokenProperties values. E.g. to override the expiration time of tokens you can add security.jwt.expiration=your_value to the application.properties file.

Built With

Screenshots

login page cookies