6 javascript adal.js azure-ad-msal microsoft-teams
经过两个月的通过 adal.js 和 msal.js 尝试 Teams 身份验证并失败后,我几乎要放弃了。所以我真的需要你的帮助。
基本上,我需要在我使用 App Studio 创建的应用程序中为我自己的网站(选项卡)“静默”验证登录的 Teams 用户。这样做的原因是,这样我就可以使用身份验证令牌的数据来登录我自己的网站。
到目前为止,我只能使用 msal.js 和一个弹出窗口来实现这一点,根据我问过的团队开发人员,这不是要走的路。可以理解,因为我无法在 Teams 客户端上使用弹出方法,因为它被阻止了。
我已经尝试过这种向我推荐的静默登录方法(https://github.com/OfficeDev/microsoft-teams-sample-complete-node/blob/master/src/views/tab-auth/silent.hbs) . 遗憾的是它没有奏效。我得到的只是“更新失败:由于超时,令牌更新操作失败”错误。
由于之前在web浏览器中使用过的msal.js popup变种(Node.js Azure Quick Start Example),我认为Azure App的配置没有错误。
到目前为止,这是我的代码:
// onLoad="prepareForm()"
<!--- Import package for authentication information in Teams/Azure--->
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.15/js/adal.min.js" integrity="sha384-lIk8T3uMxKqXQVVfFbiw0K/Nq+kt1P3NtGt/pNexiDby2rKU6xnDY8p16gIwKqgI" crossorigin="anonymous"></script>
<script src="https://statics.teams.microsoft.com/sdk/v1.4.2/js/MicrosoftTeams.min.js" crossorigin="anonymous"></script>
<script language="JavaScript">
let config = {
clientId: "1402f497-d6e8-6740-9412-e12def41c451", // I've changed it for this stackoverflow post
redirectUri: "https://myredirect.com", // I've changed it for this stackoverflow post
cacheLocation: "localStorage",
navigateToLoginRequestUrl: false,
};
microsoftTeams.initialize()
/// START Functions for Teams
function getTeamsContext() {
microsoftTeams.getContext(function(context) {
startAuthentication(context);
});
}
function startAuthentication(teamsContext) {
if (teamsContext.loginHint) {
config.extraQueryParameters = "scope=openid+profile&login_hint=" + encodeURIComponent(teamsContext.loginHint);
} else {
config.extraQueryParameters = "scope=openid+profile";
}
let authContext = new AuthenticationContext(config);
user = authContext.getCachedUser();
if (user) {
if (user.profile.oid !== teamsContext.userObjectId) {
authContext.clearCache();
}
}
let token = authContext.getCachedToken(config.clientId);
if (token) {
console.log(token)
// Get content of token
} else {
// No token, or token is expired
authContext._renewIdToken(function (err, idToken) {
if (err) {
console.log("Renewal failed: " + err);
// Some way of logging in via Popup or similiar
} else {
console.log(idToken)
// Get content of token
}
});
}
}
/// END Functions for Teams
// initialized on page load!
function prepareForm() {
getTeamsContext();
document.InputForm.password.focus()
}
<script/>
Run Code Online (Sandbox Code Playgroud)
这些是我的问题:
| 归档时间: |
|
| 查看次数: |
1718 次 |
| 最近记录: |