Giter VIP home page Giter VIP logo

oauth2-stateless-authentication-with-spring-and-jwt-token's Introduction

Oauth2 Stateless Authentication with Spring and JWT Token

This project uses Spring Security to authenticate and protect some Rest resources. It uses withAuthorizationServerConfigurerAdapter, ResourceServerConfigurerAdapter and WebSecurityConfigurerAdapter combined with @PreAuthorize to configure the security. It also uses an H2 embeded database to authenticate the users.

Article on the project

USING SPRING OAUTH2 TO SECURE REST

External references

This project was inspired by all these references.
  • Using JWT with Spring Security OAuth
  • JWT authentication with Spring Web
  • JWT Authentication Tutorial: An example using Spring Boot
  • Spring Oauth2 with JWT Sample
  • OAuth2 in depth: A step-by-step introduction for enterprises
  • spring-auth-example

    To Build and Run

    Go to the cloned directory and run mvn spring-boot:run or build with your chosen IDE.

    Curl Commands

    You should install ./JQ before running these Curl commands.
    To get a new token
    curl trusted-app:secret@localhost:8080/oauth/token -d "grant_type=password&username=user&password=password" | jq
    To get a refresh token
    curl trusted-app:secret@localhost:8080/oauth/token -d "grant_type=access_token&access_tokem=[ACCESS_TOKEN]" | jq
    To access a protected resource
    curl -H "Authorization: Bearer [ACCESS_TOKEN]" localhost:8080/api/hello

    Register new Account
    curl -H "Authorization: Bearer $(curl register-app:secret@localhost:8080/oauth/token -d "grant_type=client_credentials&client_id=register-app" | jq --raw-output ."access_token")" localhost:8080/api/register -H "Content-Type: application/json" -d '{"username":"new-user","password":"password","firstName":"First","lastName":"Last","email":"[email protected]"}' | jq

    Curl sample commands api/me curl -H "Authorization: Bearer $(curl trusted-app:secret@localhost:8080/oauth/token -d "grant_type=password&username=user&password=password" | jq --raw-output ."access_token")" localhost:8080/api/me | jq

  • oauth2-stateless-authentication-with-spring-and-jwt-token's People

    Contributors

    thejavamonk avatar tinmegali avatar

    Stargazers

     avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

    Watchers

     avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

    oauth2-stateless-authentication-with-spring-and-jwt-token's Issues

    Decode token

    Hello guy i make my project and and use the same code with you to do authentication, but on my case i use spring boot 1.5, and when i try do some requistion the application say it :

    o.s.s.c.bcrypt.BCryptPasswordEncoder : Encoded password does not look like BCrypt

    you know this ?

    GrantType='authorization_code' 401

    Hello,your code is very useful for me,but I meet a problem.When i test the authorization_code grant type it appear 401 error.My test code is here.Can you help me fix this problem? Thank you!

    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.