Implementation of JWT Token - vignesh01105/UserLoginSystem GitHub Wiki
Generate JWT Token
- To generate Token, there are few important fields like username, Issue date, expiry date and password
- We considered all fields is under claim, to add claim we have to add username, issue date and expiry date in code.
- And create key to add digital signature with token. scenario of verify this one is valid token.
Validate the Token
- At first time, the user is login with credentials and get token from the server.
- when the user access the resources in application, it will send back the token in authorization header to server.
- To validate token there are steps to be followed.
- At first,in security config we have to add JWT Filter in security filter chain. Add this filter chain in place before UsernamePasswordAuthenticationToken
- In JWT Filter, extract token from Authorization Header and retrive the username and token.
- By retrive the username, checking the userdetails service by validating data from the DB.
- By retrive token, checking the expiration and check its valid.
- once it is valid, sending the userdetails data to next filter chain (UsernamePasswordAuthenticationToken).