我正在为 Outlook 创建 Web 加载项。 Outlook 服务器正在交换。我想从我的附加组件中的 Microsoft Graph 获取数据。
我已根据本指南在 Azure AD 中注册了应用程序:https://learn.microsoft.com/en-us/office/dev/add-ins/develop/create-sso-office-add-ins-aspnet
我根据这个模板编辑了清单:
<WebApplicationInfo>
<Id>Enter_client_ID_here</Id>
<Resource>api://localhost:44355/Enter_client_ID_here</Resource>
<Scopes>
<Scope>Files.Read</Scope>
<Scope>profile</Scope>
<Scope>openid</Scope>
</Scopes>
</WebApplicationInfo>
我在脚本中添加了一段代码,该代码应该下载一个令牌,我可以使用该令牌通过 Graph 来验证自己的身份:
Office.context.auth.getAccessTokenAsync(function (result) {
if (result.status === 'succeeded') {
// Use this token to call Web API
var ssoToken = result.value
} else {
if (result.error.code === 13003) {
// SSO is not supported for domain user accounts, only
// work or school (Office 365) or Microsoft Account IDs.
console.log(result.error)
} else {
// Handle error
console.log(result.error)
}
}
})
不幸的是,在下载令牌时,它抛出了代码13006的错误。在文档中,我不明白如何修复它。有谁知道如何做到这一点?也许我错过了什么。
Office 插件 Web 项目采用 .NET Framework 4.8
我尝试刷新页面(按照文档的建议),但没有帮助。
编辑
我能够获取访问令牌,但当我尝试从 Microsoft Graph 获取某些内容时,出现 401 错误。代码如下:
const accessToken = await OfficeRuntime.auth.getAccessToken({ allowSignInPrompt: true })
const me = await axios.get(`https://graph.microsoft.com/v1.0/me`, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
})
我是不是搞错了?