oauth-2.0 - 在 Outlook 365 Web 插件 13005 中获取 SSO 时出错。缺少预授权
问题描述
我正在开发一个 Outlook 加载项,我正在尝试获取 SSO 令牌来调用 Graph API。我指的是这个链接来开发我的插件Outlook 插件 SSO。我在 Azure AD(多租户)中注册了我的应用程序。一步一步地跟随一切
我将版本覆盖添加到清单
<Id>Client_id-xxx-xxx</Id>
<Resource>api://localhost:44361/Client_id-xxx-xxx</Resource>
<Scopes>
<Scope>openid</Scope>
<Scope>offline_access</Scope>
<Scope>profile</Scope>
<Scope>Files.ReadWrite</Scope>
<Scope>Mail.Read</Scope>
<Scope>User.Read</Scope>
<Scope>email</Scope>
</Scopes>
</WebApplicationInfo>
authconfig.js
var authConfig = {
clientId:"Client_id-xxx-xxx",
scopes: "Files.ReadWrite Mail.Read openid offline_access profile email User.Read",
redirectUrl: "https://localhost:44361/MessageRead.html"
};
网页配置
<appSettings>
<add key="ida:AppId" value="Client_Id_xx-xx" />
<add key="ida:Audience" value="Client_id_xx_xx" />
<add key="ida:AppPassword" value="app_Password" />
<add key="ida:RedirectUri" value="https://localhost:44361/MessageRead.html" />
<add key="ida:Authority" value="https://login.microsoftonline.com/common/oauth2/v2.0" />
</appSettings>
我的 JavaScript 代码:
Office.initialize = function (reason) {
// console.log("In Office.initialize ", reason);
$(document).ready(function () {
// console.log("In Office.ready ");
if (OfficeHelpers.Authenticator.isAuthDialog()) return;
var element = document.querySelector('.ms-MessageBanner');
messageBanner = new fabric.MessageBanner(element);
messageBanner.hideBanner();
authenticator = new OfficeHelpers.Authenticator();
authenticator.endpoints.registerMicrosoftAuth(authConfig.clientId, {
redirectUrl: authConfig.redirectUrl,
scope: authConfig.scopes
});
//loadProps();
});
};
function GetSSOToken(DataObj) {
var attachmentIds = getAttechamentIdList();
//if (Office.context.auth !== undefined && Office.context.auth.getAccessToken !== undefined) {
if (OfficeRuntime.auth !== undefined && OfficeRuntime.auth.getAccessToken !== undefined) {
OfficeRuntime.auth.getAccessToken().then(function (result) {
if (result.status === "succeeded") {
// No need to prompt user, use this token to call Web API
saveEmailWithSSO(result.value, attachmentIds, DataObj);
} else if (result.error.code == 13007 || result.error.code == 13005) {
console.log('error:', result.error.code);
// These error codes indicate that we need to prompt for consent
// Office.context.auth.getAccessTokenAsync({ forceConsent: true }, function (result) {
OfficeRuntime.auth.getAccessToken({ allowConsentPrompt: true, allowSignInPrompt: true }, function (result) {
if (result.status === "succeeded") {
console.log('AccessToken:', result.value);
saveEmailWithSSO(result.value, attachmentIds, DataObj);
} else {
// Could not get SSO token, proceed with authentication prompt
console.log('in with prompt else1 ');
// console.log('error:', result.error.code);
saveEmailWithPrompt(attachmentIds);
}
});
} else {
// Could not get SSO token, proceed with authentication prompt
console.log('in with prompt else2 ');
console.log('error:', result.error.code);
saveEmailWithPrompt(attachmentIds);
}
}).catch(function (error) {
console.log('in catch', error);
});
}
上面的代码总是在 Catch 块中结束,错误 13005,缺少预授权,缺少此插件的授权。
我已经参考并从此链接进行了更改https://github.com/OfficeDev/office-js/issues/923 即使这里的类似问题也无法解决。请建议还有什么可以解决的。
我正在尝试使用全局管理员的 Outlook 帐户和来自外部租户的另一个用户运行此代码。但在这两种情况下都不起作用。
- - - 更新 - -
经过一些工作后,我可以在登录时看到这个问题(在使用 forceConsent allowConsentPrompt 时)我可以看到这个错误
解决方案
解决了 !经过数小时的头脑风暴,我能够通过再次修改文档来解决此错误。我忽略了https://docs.microsoft.com/en-us/office/dev/add-ins/develop/register-sso-add-in-aad-v2的第 12 步
推荐阅读
- javascript - 如何从迭代方法编写递归函数?
- docker - Symfony NotBlank 约束允许空白字符串
- c - 是否可以阻止单个翻译单元或部分翻译单元的优化?
- c# - Tizen .NET 可穿戴屏幕唤醒
- excel - 无法取消隐藏保存在 Excel 97 版本中的工作表
- java - 将本地文件解析为 IEditiorInput -Eclipse 插件调试器开发
- html - 在百分比范围内显示颜色阴影
- webpack - 为什么“webpack”项无法识别为 cmdlet、函数
- java - Java:存储字符串集的最佳数据结构,而不是逐个字符地重新散列
- javascript - 读取 JSON 文件