gpt4 book ai didi

adal - 如何检查 AuthenticationContext 是否与 Azure AD 有连接?

转载 作者:行者123 更新时间:2023-12-03 02:24:55 24 4
gpt4 key购买 nike

我目前正在尝试连接到我的 AD 以接收缓存的用户/ token 或我自己的 Vue.js 应用程序在我的团队应用程序中的新 token 。

到目前为止,我已经创建了一个 Teams 应用程序来获取我的用户的上下文、一个 Azure 应用程序连接到和一个 Vue.js 应用程序来测试 microsoftTeams SDK 和 Adal.js 包。

这是我目前的方法:

import * as microsoftTeams from '@microsoft/teams-js';
import * as AuthenticationContext from 'adal-angular/lib/adal';

// some other code that is not relevant to this...

async loginWithTeamsCredentials() {

await microsoftTeams.initialize();

microsoftTeams.getContext(async (context) => {
const { loginHint } = context;

const config = {
clientId: 'some ClientID that I replaced with nonsense for this stackoverflow post',
redirectUri: 'https://login.microsoftonline.com/common/oauth2/nativeclient',
cacheLocation: 'localStorage',
navigateToLoginRequestUrl: false,
};

if (loginHint) {
config.extraQueryParameter = `scope=openid+profile&login_hint=${encodeURIComponent(
loginHint,
)}`;
} else {
config.extraQueryParameter = 'scope=openid+profile';
}

const authContext = new AuthenticationContext(config);

const user = await authContext.getCachedUser();

console.log(user);
});
},

问题是,即使他存在于我浏览器的 localStorage 中,用户也将始终为空。因此,我不确定是否通过 AuthenticationContext 对象与我的 AD 建立了连接。我的代码中的配置包含必要的信息,也应该是正确的。我还通过此代码获得了我的 microsoftTeams SDK 上下文的 loginHint,所以这也不是问题。

我在这里做错了什么?

最佳答案

我认为您的问题是您使用 adal.js 而不是 Azure AD v2 所需的 msal.js。使用 msal.js 和相应的方法,您应该获得连接。

另一件事是您不能在 Teams 中使用 msal 进行静默身份验证。但我无法告诉您如何仅从 Teams SDK 获取信息。

关于adal - 如何检查 AuthenticationContext 是否与 Azure AD 有连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59209405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com