authentication - 微软团队身份验证
问题描述
我开发了一个自定义团队应用程序,它有一个基本选项卡,用户必须在其中登录才能查看某些内容。身份验证通过 Oauth2 代码流,使用外部 npm 包 (@openid/appauth)。当用户单击登录按钮时,我创建了此代码以打开弹出窗口:
login = () => {
const successCallback = (result) => {
this.props.setLogged(result);
}
const failureCallback = (error) => {
logger.warn(JSON.stringify(error));
this.props.setError(error);
}
authClient.teamsAuthRequest(this.props.user.PartitionKey, this.props.user.RowKey, successCallback, failureCallback);
}
此功能:teamAuthRequest 只是用于调用授权端点的配置:
teamsAuthRequest: async (tid, aaId, successCallback, failureCallback) => {
const config = await createConfiguration();
const request = createAuthRequest(tid, aaId);
teamsHandler.performAuthorizationRequest(config, request, successCallback, failureCallback);
}
它通过以下代码调用一个打开弹出窗口的函数:
microsoftTeams.authentication.authenticate({
url: url,
width: 600,
height: 550,
successCallback: function (result) {
successCallback(result);
},
failureCallback: function (reason) {
failureCallback(reason)
}
});
如果我使用团队网络,它会正确打开弹出窗口并在登录后关闭它。
如果我在团队桌面中使用相同的应用程序,它会正确打开弹出窗口,但它永远不会调用 notifySuccess 函数,也永远不会关闭弹出窗口。
当我收到来自外部提供商的回调以接收授权代码时,我运行此代码:
if (response) {
authClient.getToken(request && request.internal && request.internal.code_verifier, response.code)
.then((oResponse) => {
user = {
PartitionKey: request.extras.tid,
RowKey: request.extras.aaId,
AccessToken: oResponse.accessToken,
RefreshToken: oResponse.refreshToken
}
microsoftTeams.authentication.notifySuccess(user)
})
.catch(oError => {
microsoftTeams.authentication.notifyFailure(oError)
});
}
我该如何解决?
解决方案
Teams 基本上会使用microsoftTeams.authentication.authenticate
. 结果,即使您看到弹出窗口,您实际上也想使用重定向流。请在此处查看说明此问题的示例应用程序
https://github.com/pnp/teams-dev-samples/tree/master/samples/tab-sso
推荐阅读
- google-chrome-extension - 如何为 Chrome 链接到文本片段 URL 添加书签?
- html - 需要缩放 SVG 帮助
- python - python有没有办法通过从conf文件中读取源目录和目标目录来移动windows上的文件?
- html-table - Material UI 创建多行数据表行
- javascript - 在 Godaddy 的 Wordpress 网站中添加自定义全栈网页
- python-3.x - 如何在 django 中使用 sql 文件创建 postgresql 数据库?请逐步指导我。我有如下的sql
- api - Flutter 搜索 Spotify Song 并保存深层链接
- reactjs - 如果通过 npm 安装 react 和 react dom 包,是否需要 CDN 链接?
- javascript - 有没有办法在没有库的情况下抓取动态网站?
- flutter - 如何在颤动中为选定的复选框列表块更新表中的多条记录