Grü*_*üse 7 authentication node.js azure-active-directory azure-ad-msal
我@azure/msal-node在节点应用程序中使用该包,使我的用户能够使用其 AzureAD 凭据登录。登录和获取会话令牌工作正常,但我找不到使会话无效/注销用户的方法 - 我是否忽略了这里明显的东西?
仅供参考,以下是我获取令牌的方式:
// 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);
}
Run Code Online (Sandbox Code Playgroud)
在重定向处理程序中,我这样做:
const tokenResponse = await msalApp.acquireTokenByCode({
code: request.query.code,
scopes: ['user.read'],
redirectUri: BASE_URL + '/msal-redirect'
});
Run Code Online (Sandbox Code Playgroud)
然后我使用该令牌来显示登录的用户等。
我缺少的是类似的东西msalApp.logout()- 我在这里没有看到什么?
遗憾的是,MSAL 目前不包含msalApp.logout()API。相反,您必须手动实施这些步骤。
注销操作将包含多个步骤:
要从 msal 应用程序缓存中删除帐户和令牌,您可以执行以下操作:
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);
Run Code Online (Sandbox Code Playgroud)
要从 AAD 注销,您必须将用户重定向到 Azure AD 注销终结点。这里的文档应该解释如何制作这个请求。
| 归档时间: |
|
| 查看次数: |
7941 次 |
| 最近记录: |