我可以通过重写
SavedRequestAwareAuthenticationSuccessHandler
并将其添加到我的安全配置中:
http....
.and().oauth2Login().successHandler(authCodeCachingSuccessHandler)
我缓存代码并传递给超类来处理:
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
Map<String, String[]> parameterMap = request.getParameterMap();
String[] s = parameterMap.get("code");
tokenCache.setAuthCode( (DefaultOidcUser) authentication.getPrincipal(), s[0] );
super.onAuthenticationSuccess(request, response, authentication);
}