微软团队身份验证
Microsoft Teams Authentication
我开发了一个自定义 Teams 应用程序,它有一个基本选项卡,用户必须在其中登录才能查看某些内容。
身份验证基于 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);
}
此功能:teamsAuthRequest 仅用于调用授权端点的配置:
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
为您启动登录弹出窗口。结果,即使您 - 看到 - 一个弹出窗口,您实际上想要使用 redirect 流程。请在此处查看说明此内容的示例应用程序
https://github.com/pnp/teams-dev-samples/tree/master/samples/tab-sso
我开发了一个自定义 Teams 应用程序,它有一个基本选项卡,用户必须在其中登录才能查看某些内容。 身份验证基于 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);
}
此功能:teamsAuthRequest 仅用于调用授权端点的配置:
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
为您启动登录弹出窗口。结果,即使您 - 看到 - 一个弹出窗口,您实际上想要使用 redirect 流程。请在此处查看说明此内容的示例应用程序
https://github.com/pnp/teams-dev-samples/tree/master/samples/tab-sso