我正在使用 @azure/msal-node
打包在 Node 应用程序中,以使我的用户能够使用他们的 AzureAD 凭据登录。登录和获取 session token 工作正常,但我找不到使 session 无效/注销用户的方法 - 我在这里忽略了一些明显的东西吗?
就上下文而言,这是我获取 token 的方式:
// msalConfig is my valid config object
const msalApp = new msal.ConfidentialClientApplication(msalConfig);
const authCodeUrlParameters = {
scopes: ['user.read'],
redirectUri: BASE_URL + '/msal-redirect'
};
try {
const authCodeResponse = await msalApp.getAuthCodeUrl(authCodeUrlParameters);
reply.redirect(authCodeResponse);
} catch (e) {
logError('auth code redirect error', e);
}
在重定向处理程序中,我这样做:const tokenResponse = await msalApp.acquireTokenByCode({
code: request.query.code,
scopes: ['user.read'],
redirectUri: BASE_URL + '/msal-redirect'
});
然后我使用该 token 来显示登录用户等。我缺少的是
msalApp.logout()
- 我在这里没看到什么?
最佳答案
不幸的是,MSAL 目前不包含 msalApp.logout()
API。相反,您将不得不手动实现这些步骤。
注销操作将包含多个步骤:
要从 msal 应用程序缓存中删除帐户和 token ,您可以执行以下操作:
const accounts = msalApp.getTokenCache().getAllAccounts();
// filter on the account that you want to delete from the cache.
// I take the first one here to keep the code sample short
const account = accounts[0];
msalApp.getTokenCache().removeAccount(account);
要从 AAD 注销,您必须将用户重定向到 Azure AD 注销终结点。 documentation here应该解释如何制作这个请求。
关于node.js - @azure/msal Node : Is there a way to log out/invalidate tokens?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64199637/