How to obtain refresh token
MRHarrison opened this issue · 3 comments
MRHarrison commented
@murraco How do I obtain a refresh token? I see it mentioned briefly but not sure of how to implement in this auth flow.
rohitkrishna094 commented
I would like to know about that as well. Were you able to figure it out? Thanks
HaniSWE commented
Just add this method to the UserController
:
@GetMapping("/refresh")
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_CLIENT')")
public String refresh(HttpServletRequest req) {
return userService.refresh(req.getRemoteUser());
}
And one for the UserService
:
public String refresh(String username) {
return jwtTokenProvider.createToken(username,
userRepository.findByUsername(username).getRoles());
}
In this way you will create an endpoint to refresh your current token with a new one. Remember than to access this endpoint you must be authenticated.
hanzhaogang commented
Just add this method to the
UserController
:@GetMapping("/refresh") @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_CLIENT')") public String refresh(HttpServletRequest req) { return userService.refresh(req.getRemoteUser()); }And one for the
UserService
:public String refresh(String username) { return jwtTokenProvider.createToken(username, userRepository.findByUsername(username).getRoles()); }In this way you will create an endpoint to refresh your current token with a new one. Remember than to access this endpoint you must be authenticated.
This solution is different with Refresh token.