We set up a custom AuthenticationSuccessHandler (the source code for this class is shown next) in our Spring Security configuration class. On successful authentication, it will generate the JWT and also set a HTTP response header:
- Header name: Authorization
- Header value: Bearer JWT
Let's take a look at the following code:
public class JWTAuthSuccessHandler implements ServerAuthenticationSuccessHandler{ @Override public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange, Authentication authentication) { ServerWebExchange exchange = webFilterExchange.getExchange(); exchange.getResponse() .getHeaders() .add(HttpHeaders.AUTHORIZATION, getHttpAuthHeaderValue(authentication)); return webFilterExchange.getChain().filter(exchange); ...