团队选项卡身份验证

Teams tab authentication

我正在尝试弄清楚如何使用 microsoftTeams.authentication.authenticate() 函数,但我真的很困惑。当我调用该函数时,会在我的浏览器 (Chrome) window 中打开一个新选项卡,而不是在 Teams 本身中。这是正常行为吗?身份验证工作并重定向到回调 url,我在其中调用 microsoftTeams.authentication.notifySuccess() 函数,但它不会返回到 microsoftTeams.authentication.authenticate() 成功回调(总是点击失败回调)。这是 validDomains 的问题吗?我很迷路。任何帮助都会很棒!谢谢。

microsoftTeams.authentication.authenticate({
    url: "/auth",
    width: 500,
    height: 500,
    successCallback: () => {
        alert("auth success")
        // Redirect to app
        window.location.href = "/app"
    },
    failureCallback: () => {
        alert("auth failure")
    }
})

我想通了。

我错误地在页面加载时调用了 microsoftTeams.authentication.authenticate() 函数,而不是在单击登录按钮等用户交互时调用。

参考:"Add UI to your configuration or content page to enable the user to sign in when necessary. You should not drive the authentication pop-up without user action, because this is likely to trigger the browser's pop-up blocker."