Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Oauth2 Stateless Authentication with Spring and JWT Token

License

NotificationsYou must be signed in to change notification settings

tinmegali/Oauth2-Stateless-Authentication-with-Spring-and-JWT-Token

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project usesSpring Security to authenticate and protect some Rest resources. It useswithAuthorizationServerConfigurerAdapter,ResourceServerConfigurerAdapter andWebSecurityConfigurerAdapter combined with@PreAuthorize to configure the security. It also uses anH2 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 runmvn 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@email.com"}' | jq

    Curl sample commandsapi/mecurl -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

  • About

    Oauth2 Stateless Authentication with Spring and JWT Token

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Contributors2

    •  
    •  

    [8]ページ先頭

    ©2009-2025 Movatter.jp