Published
- 1 min read
spring boot get header authorization
The solution for this is noted below
spring boot get header authorization
Solution
@PostMapping("/get-token")
public ResponseEntity ResetPasssword(@RequestHeader HttpHeaders headers){
String token = headers.getFirst(HttpHeaders.AUTHORIZATION);
System.out.print(token);
// String PassResponse = userServices.ResetPassWithJWT(PostDta,token).toString();
return new ResponseEntity(token, HttpStatus.OK);
}
//this is another method you can also get the token with this method
public String GetToken(HttpServletRequest request){
String token =null;
final String authorizationHeaderValue = request.getHeader("Authorization");
if (authorizationHeaderValue != null && authorizationHeaderValue.startsWith("Bearer")) {
token = authorizationHeaderValue.substring(7, authorizationHeaderValue.length());
}
return token;
}
Try other methods by searching on the site. That is if this doesn’t work