当 RedirectURI returns 到受保护的应用程序时注销所有帐户

Sign Out Of All Accounts When RedirectURI returns to guarded application

我正在使用 MSALjs 在我的应用程序上注销用户。当 msalService.logoutRedirect() 被触发时,页面重定向并注销。但是,我的应用程序没有“不受保护”的路由,因此注销后的重定向 (postLogoutRedirectUri) 设置为 return 到应用程序的最后一个活动页面。当它 return 发送到应用程序时,MSAL 防护会自动找到有效的 MS 会话并自动重新登录(重定向后)。

如果我将 postLogoutRedirectUri 更改为 https://login.microsoftonline.com/common/oauth2/logout,注销确实有效并且我已正确注销。但是,我希望系统立即提示我重新登录,这就是为什么我打算 return 连接到应用程序以便 MsalGuard 可以提示登录的原因。

根据最近的 GitHub issue,一位 MSAL 贡献者说了以下内容:

This is a nuance of how B2C works. By default B2C might not log you out of your federated identity provider when you call the logout endpoint, this is explained in more detail here. I unfortunately don't know enough about B2C configuration to give you a definitive answer but you may need to create a custom policy which redirects to the AAD logout endpoint you mentioned: 'https://login.microsoftonline.com/common/oauth2/logout' as this endpoint is the one that ultimately closes your session with AAD. You can also have B2C pass through your postLogoutRedirectUri to this endpoint so that AAD redirects you back to your application after the logout instead of ending on the "Close this window" screen, if desired.

如何设置才能正确触发注销并注销所有会话?

此外,如果我手动更改 openid-config 的元数据,使 "end_session_endpoint" 等于上面的 microsoftonline logout link,该行为似乎更符合我的要求会期待。

您可以将应用程序 post logout redirect uri 发送到联合 IdPs logout url。您可以在 MSAL 配置对象中设置 postLogoutRedirectURI。

并在联合 IdP 处,将注销 url 设置为应用程序。

该方法仅在您使用 1 个联合 IdP 时有效,并且是唯一可用的 IdP。


function signOut() {
    const logoutRequest = {
     postLogoutRedirectUri: "https://login.microsoftonline.com/common/oauth2/v2.0/logout?
post_logout_redirect_uri=https://myapp.com"
     msalConfig.auth.redirectUri
    };
    myMSALObj.logoutPopup(logoutRequest);
}

否则,请在您的应用中创建一个重定向到受保护页面的不受保护页面,但将 MSAL 提示参数设置为“登录”。至少 B2C 登录页面会出现,并允许用户 select 他们想要登录的方式。如果他们 select 联合 IdP,他们仍可能获得 SSO。