Microsoft Q&A
使用此标记与 Microsoft 问答团队共享建议、功能请求和 bug。 Microsoft 问答团队将定期评估你的反馈,并在此过程中提供更新。
162 个问题
I try to enable logout without re-selecting the account in Microsoft Azure SSO, so I enable login_hint and then implement the code in my application to pass the login_hint parameter to the logout_hint and attach to the URL. But when I logout, the logout_hint is not attached to the URL and still need to select the account.
I try to follow the description in Microsoft Azure official document, to enable the login_hint in the application configuration in Azure and also implemented the related codes in my application.
here is my code:
@RequestMapping("/logout")
public void logout(HttpServletRequest httpRequest, HttpServletResponse response) throws IOException {
// 从会话中获取 login_hint(用户登录时存储的唯一标识,比如userId或email)
String loginHint = (String) httpRequest.getSession().getAttribute("login_hint");
log.info("loginHint: {}", loginHint);
// Invalidate session
httpRequest.getSession().invalidate();
// 构建注销 URL,加入 logout_hint 参数
String logoutUrl = endSessionEndpoint + "?post_logout_redirect_uri=" + URLEncoder.encode(redirectUrl, StandardCharsets.UTF_8);
if (loginHint != null) {
logoutUrl += "&logout_hint=" + URLEncoder.encode(loginHint, StandardCharsets.UTF_8);
}
response.sendRedirect(logoutUrl);
}
@GetMapping("/login")
public TideResponse<LoginResp> loginWithToken(@RequestParam("token") String token, HttpServletRequest request) {
TideResponse<LoginResp> tideResponseResponseEntity;
//校验token
JwtHelper.isTokenValid(token);
String userName = JwtHelper.extractUserName(token);
log.info("Extract username is {}", userName);
// 将 userName 作为 login_hint 放置到 session 中
request.getSession().setAttribute("login_hint", userName);
try {
tideResponseResponseEntity = userClient.microsoftLogin(userName);
} catch (Exception e) {
throw new CustomException(SysCodeMenu.CODE829);
}
return tideResponseResponseEntity;
}