我怎么知道我已经在 angular 应用程序中单点登录了?

How do I know that I already single sign-on in angular application?

我使用 https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/docs/v2-docs/configuration.md 在 angular 中设置单点登录。所以如果我点击登录按钮,我就可以登录了。

我的问题是,如果在其他地方我已经使用我公司的凭据登录,那么我不需要在 angular 应用程序中再次登录。我的 angular 应用程序如何知道我已经签名?因此我不需要导航到登录组件并再次单击登录按钮?

The msal-browser library provides the following APIs to access cached accounts:

  • getAllAccounts(): returns all the accounts currently in the cache. An application must choose an account to acquire tokens silently.
  • getAccountByHomeId(): receives a homeAccountId string and returns the matching account from the cache.
  • getAccountByLocalId(): receives a localAccountId string and returns the matching account from the cache.
  • getAccountByUsername(): receives a username string and returns the matching account from the cache.

[ ... snip ... ]

The current msal-browser default sample has a working single account scenario.

来源:Accounts in MSAL Browser.

示例代码的一部分:

const myMSALObj = new msal.PublicClientApplication(msalConfig);

myMSALObj.handleRedirectPromise().then(handleResponse).catch(err => {
    console.error(err);
});

function handleResponse(resp) {
    if (resp !== null) {
        accountId = resp.account.homeAccountId;
        myMSALObj.setActiveAccount(resp.account);
        showWelcomeMessage(resp.account);
    } else {
        const currentAccounts = myMSALObj.getAllAccounts();
        if (!currentAccounts || currentAccounts.length < 1) {
            return;
        } else if (currentAccounts.length === 1) {
            const activeAccount = currentAccounts[0];
            myMSALObj.setActiveAccount(activeAccount);
            accountId = activeAccount.homeAccountId;
            showWelcomeMessage(activeAccount);
        }
    }
}