Giter Club home page Giter Club logo

jwt-auth-flow-spring-security's Introduction

JWT Authorization flow using Spring Security

A reference proof-of-concept that leverages Spring-security to implement JWT based Authentication and Authorization.
๐Ÿ›  upgraded to Spring Boot 3 and Spring Security 6 ๐Ÿ› 

Important classes

Any request to an endpoint that is specified to be authenticated will be intercepted by the JwtAuthenticationFilter which is configured in the SecurityConfiguration, Any APIs that need to be made public can be specified under the appropriate HTTP method in ApiPathExclusion.

Inside JwtAuthenticationFilter, the token from request header Authorization is extracted and decrypted, the corresponding user in database is fetched and is loaded onto the SecurityContextHolder object which signifies the current logged-in user for that HTTP request. The user details are added as part of custom claims in generated JWT. [refer JwtUtility]

The secret key which is to be used for JWT generation and decryption, along with Access-token and Refresh-token validity can be specified in application.properties file corresponding to JwtConfigurationProperties.java. Below is a sample .properties file snippet that can be used to configure the required parameters.

# JWT Configuration
com.behl.cerberus.jwt.secret-key=093617ebfa4b9af9700db274ac204ffa34195494d97b9c26c23ad561de817926
com.behl.cerberus.jwt.access-token.validity=30
com.behl.cerberus.jwt.refresh-token.validity=5

Local Setup

Run the below given commands in the projects base directory to create an image and start a container from the given Dockerfile

docker build -t jwt-auth-flow-spring-security .
docker container run -d -p 8080:8080 jwt-auth-flow-spring-security

Demonstration screen recording

jwt-auth-flow-spring-security-swagger-ui-demonstration-screen-recording.mov

jwt-auth-flow-spring-security's People

Contributors

hardiksinghbehl avatar

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.