azure - Azure AD OAuth2AuthorizationResponse 的授权代码
问题描述
我已经按照此处指定的方式启动并运行了 Springboot Active Directory 示例:
我可以使用我创建并授予“Windows Azure Active Directory”权限的客户端 ID 使用我的 Azure AD 凭据登录。
下一步是我想获取登录用户的头像,所以我需要从OAuth2AuthorizationResponse
我不清楚如何访问这些数据。它在返回的 OAuth2User 对象中不可用
我尝试在 /login/oauth2/code/azure 上设置一个 HandlerInterceptor,这样我就可以拦截响应,但这永远不会被击中(?)
我还尝试添加自定义过滤器:
http.addFilterAfter(
new CustomFilter(), BasicAuthenticationFilter.class)
但这永远不会被/login/oauth2/code/azure
URI击中
解决方案
我能够通过覆盖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);
}
我怀疑这是“最佳实践”,但它确实有效,而且我还没有找到更优雅的方法
推荐阅读
- python - Python tkinter overrideredirect 隐藏在任务栏中
- python-3.x - 使用 filedialog 时隐藏 tk 窗口
- php - filter_var() 未检测到保留的 IP
- python - Python 中装饰器的冗余函数调用
- node.js - 如何返回从 MongoDb 中的一个过滤的多个数组
- sql - 自窗口内最后一个最大值以来的计数
- c - 嵌入式 C (FreeRTOS)
- r - “subset()”函数的不同表达式中的一种方法在R中失败了
- python - Mandelbrot 使用枕头库在 python 中设置放大
- c++ - 在 CodeBlocks 中使用 libnoise