office-js - 使用 Office-js-helpers 或 Office.context.ui.displayDialogAsync 时出现错误 12002
问题描述
我正在使用 Office-js-helpers 和 Office.context.ui.displayDialogAsync 在我们的 Outlook 加载项中对用户进行身份验证。对话框打开很好,我可以使用我们的 IdentityServer4 url 进行身份验证(例如 /connect/authenticate 与 redirectUrl window.location.origin)。但是,如果我的加载项文件夹中没有 Index.html,我会在 DialogEventReceived 处理程序中收到 12002 错误,这意味着对话框无法加载 url。如果我在我的加载项文件夹中添加 Index.html(例如 window.location.origin 将是https://localhost:44352/Index.html ) ,我不会收到此错误- 但没有任何反应。DialogMessageReceived 句柄永远不会触发。我使用 office-js 的 Authenticator.authenticate 和 displayDialogAsync 得到了同样的行为。
请参阅下面的片段,这些片段在对话框中验证良好,但我无法获取令牌/代码,因为 DialogMessageReceived 永远不会触发或出错。
使用 Office-js-helpers
authenticator.endpoints.add("RM", {
provider: 'RM',
clientId: "MyClientId",
baseUrl: "MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer",
authorizeUrl: "/connect/authorize",
tokenUrl: "MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer/connect/token",
redirectUrl: window.location.origin,
responseType: "code",
state: true,
scope: "openid profile onelist offline_access"
});
authenticator.authenticate('RM', true)
.then(function (token) {
showNotification("Token: " + prettify(token));
})
.catch(function (error) {
showNotification("No Token: " + prettify(error));
});
使用对话框 API
Office.context.ui.displayDialogAsync("MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer/connect/authorize?response_type=code&client_id=MyClientID&redirect_uri=https%3A%2F%2Flocalhost%3A44352&scope=openid%20profile%20MyProfile%20offline_access&state=3364575774",
{ height: 500, width: 500 },
function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function (args) {
showNotification(prettify(args.message));
dialog.close();
});
dialog.addEventHandler(Office.EventType.DialogEventReceived, function (args) {
showNotification(prettify(args.error));
dialog.close();
});
}
);
请帮助:)我错过了什么或做错了什么?
解决方案
推荐阅读
- javascript - 在 React Native ScrollView 中放大单个项目
- javascript - 将值与 javaScript 进行比较,如果为 true,则重定向到另一个 url
- c++ - 如何在 C++ 中的函数中实现递归函数?
- php - Odoo:如何从另一个模型中检索值?
- c# - 实体框架一对一或零对自身
- python - 运行 OpenCV 给我一个 cascade.cpp:1698 错误:(-215:Assertion Failed) !empty() in function 'detectMultiScale'
- python - 是否可以使用内联 CSS 来引用 Django 中的动态图像?
- c - 为什么 mutex_unlock 可以在没有被所有者调用的情况下工作
- c# - 有什么方法可以将 WSDL 文件转换为带有操作的 C# 接口?
- python - 为 3 个不同的变量创建一个 for 循环