Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Avec112/jwtdemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JWTDemo

This applications is a demo showing how to access a secured REST api with JSON Web Token (JWT).

####We use these technologies:

  • Java 13
  • Maven 3.6.1
  • Spring Boot 2.2.1.RELEASE
    • Spring Security
    • Spring Data JPA
    • Spring Data REST
  • JWT 0.10.7
  • H2 database
  • Lombok
  • Commons-lang3

Documentation

Key generator

JWT requires a server side password
Key Generator

Warning

It is not safe to send password over http. To secure sending password please use SSL over HTTPS. This will encrypt the communication and hide your password.

How to

Use Postman, Curl or whatever is your favorite tool. I use Postman.

Send: POST -> http://localhost:8080/api/public
Result: Hello from public API controller

Send: Post -> http://localhost:8080/api/private
Result:

{
    "timestamp": "2020-02-11T10:47:43.160+0000",
    "status": 403,
    "error": "Forbidden",
    "message": "Access Denied",
    "path": "/api/private"
}

Send: POST -> http://localhost:8080/api/authenticate?username=user&password=password
Result: Look at application console output and you will se something like the following Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJzZWN1cmUtYXBpIiwiYXVkIjoic2VjdXJlLWFwcCIsInN1YiI6InVzZXIiLCJleHAiOjE1ODIyODI0MTAsInJvbCI6WyJST0xFX1VTRVIiXX0.bd2YDYt4KmXATjh45E9WtOS57UEfSP2mvhVXOTW9wMdYQr-O4aNQ6gkRn1JCQo_pAsWcnN7pjwM9mgVLgdYkTg
You can also find the token in Postman Headers from the response.

  • Copy Bearer <token> where <token> is the token from the console output or from Postman
  • Open Postman and find the GET request for /api/private and add the header 'Authorization' with value Bearer <token>

Send: GET -> http://localhost:8080/api/private
Result: Hello from private api controller

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages