首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何从所有设备中注销?

如何从所有设备中注销?
EN

Stack Overflow用户
提问于 2022-06-03 17:08:55
回答 1查看 812关注 0票数 1

我们有一个使用马萨-反应登录/注销的应用程序。

是否有一种方法可以在注销时注销用户登录的所有设备?

不幸的是,在官方的文档中找不到这方面的东西。

我们在登录方面也有问题,因此用户必须再次登录一个新选项卡(打开不同的微前端时--它们都使用相同的登录会话),尽管令牌存储在本地存储中。

希望有人能在这里提供帮助或提供文件。

EN

回答 1

Stack Overflow用户

发布于 2022-06-07 11:40:53

当您必须使用msal-react通过应用程序注销所有设备时,您肯定可以配置所需的应用程序,以便将登录应用程序的所有实例签出,如下所示:

MSAL.js v2提供了一种logoutpopup方法,用于清除浏览器存储中的缓存,并打开Azure Active Directory (Azure AD)登录页的弹出窗口。登录后,Azure将弹出重定向回您的应用程序,MSAL.js将关闭弹出窗口。

通过这种方式,您可以确保您的react应用程序已经注销了Azure Active Directory,并且所有设备都对用户注销的信息进行了反馈。

用弹出窗口登录:

代码语言:javascript
代码运行次数:0
运行
复制
 import { useMsal, AuthenticatedTemplate, UnauthenticatedTemplate } from "@azure/msal-react";

 function signOutClickHandler(instance) {
 const logoutRequest = {
    account: instance.getAccountByHomeId(homeAccountId),
    mainWindowRedirectUri: "your_app_main_window_redirect_uri",
    postLogoutRedirectUri: "your_app_logout_redirect_uri"
  }
  instance.logoutPopup(logoutRequest);
 }

// SignOutButton Component returns a button that invokes a popup logout when clicked
  function SignOutButton() {
// useMsal hook will return the PublicClientApplication instance you provided to MsalProvider
const { instance } = useMsal();

return <button onClick={() => signOutClickHandler(instance)}>Sign Out</button>
 };

  // Remember that MsalProvider must be rendered somewhere higher up in the component tree
  function App() {
   return (
    <>
        <AuthenticatedTemplate>
            <p>This will only render if a user is signed-in.</p>
            <SignOutButton />
        </AuthenticatedTemplate>
        <UnauthenticatedTemplate>
            <p>This will only render if a user is not signed-in.</p>
        </UnauthenticatedTemplate>
       </>
      )
    }

类似地,如果您引用使用重定向方法签出应用程序的方法,则必须通过设置postLogoutRedirectUri来配置它应该在签出后重定向到的URI。在应用程序注册中,应该将此URI注册为重定向URI。

有关更多信息,请参阅下面的文档链接:

https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-sign-in?tabs=react#sign-out-with-a-pop-up-window

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72493009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档