I have two applications
- authorization-server-app( base on Spring Authorization Server)
- jwt-app(oauth2 login and resource server)
jwt-app login with OAuth2.1 or OIDC , and protect resources by resource server
http.oauth2Login(oauth2LoginConfigurer -> {
oauth2LoginConfigurer.loginPage("/oauth2/authorization/toquery");
oauth2LoginConfigurer.authorizationEndpoint(authorizationEndpointConfig -> {
authorizationEndpointConfig.authorizationRequestRepository(httpCookieOAuth2AuthorizationRequestRepository);
});
oauth2LoginConfigurer.userInfoEndpoint(userInfoEndpointConfig -> {
userInfoEndpointConfig.userService(appOAuth2UserService);
userInfoEndpointConfig.oidcUserService(appOidcUserService);
});
oauth2LoginConfigurer.successHandler(appOAuth2AuthenticationSuccessHandler);
oauth2LoginConfigurer.failureHandler(appOAuth2AuthenticationFailureHandler);
});
//
http.oauth2ResourceServer(auth2ResourceServerConfigurer -> {
//
auth2ResourceServerConfigurer.bearerTokenResolver(bearerTokenResolver);
auth2ResourceServerConfigurer.accessDeniedHandler(accessDeniedHandler);
//
auth2ResourceServerConfigurer.authenticationEntryPoint(appAuthenticationEntryPoint);
auth2ResourceServerConfigurer.jwt(jwtConfigurer -> {
jwtConfigurer.jwtAuthenticationConverter(jwtAuthenticationConverter);
});
});
spring:
security:
resourceserver:
jwt:
jwk-set-uri: ${app.oauth2.domain}/oauth2/jwks
After successfully logging in through the address, I found that cookie information will be generated, which is not what I want. I want to get a jwt token after successful login, and can pass resource server。
I try to customize SimpleUrlAuthenticationSuccessHandler and use jwtencode to generate jwt token, but this will bring another problem, the token obtained by password cannot be used
I want to use the jwt token generated by authorization-server (password and authorization_code) to call normally, not the one generated in jwt-app