0

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

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

4

1 回答 1

0

msal-browser 库提供以下 API 来访问缓存帐户:

  • getAllAccounts():返回当前在缓存中的所有帐户。应用程序必须选择一个帐户以静默获取令牌。
  • getAccountByHomeId():接收一个homeAccountId字符串并从缓存中返回匹配的帐户。
  • getAccountByLocalId():接收一个localAccountId字符串并从缓存中返回匹配的帐户。
  • getAccountByUsername():接收用户名字符串并从缓存中返回匹配的帐户。

[...剪断...]

当前的msal-browser默认示例有一个有效的单帐户方案。

来源:MSAL 浏览器中的帐户

该示例代码的一部分:

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);
        }
    }
}
于 2021-08-11T14:49:00.687 回答