Added refresh token endpoint
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.responses.models.TokenResponse;
|
||||
@ -61,4 +63,16 @@ public class TokenController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/token/refresh")
|
||||
@ApiOperation(value = "Endpoint to access new token based on refresh token. It's needed when request with provided token fail with code 403")
|
||||
public ResponseEntity<TokenResponse> getRefreshToken(
|
||||
@RequestParam("refreshToken") @ApiParam(value = "Refresh token obtained in /token request") final String refreshToken) {
|
||||
User user = this.userService.getUserByRefreshToken(refreshToken)
|
||||
.orElseThrow(() -> new NullPointerException("User not found"));
|
||||
user.setToken(UUID.randomUUID().toString());
|
||||
user = this.userService.save(user);
|
||||
return new ResponseEntity<>(new TokenResponse(user), HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user