OfficeRuntime.auth.getAccessToken 在 Excel 中工作,但在 Outlook 中不起作用

发布于 2025-01-12 12:11:30 字数 3241 浏览 4 评论 0 原文

我创建了一个类似于 Graph API/Add-in 示例文档中所示的加载项和 Azure 应用程序 - https://learn.microsoft.com/en-us/graph/tutorials/office-addin

当加载项在 Excel 中运行(确保加载项可以在 Excel 中运行并使用 Excel 清单)并且对 OfficeRuntime.auth.getAccessToken 的调用返回 api 令牌时,一切正常。

如果我在 Outlook 中运行加载项(将加载项更改为在 Outlook 中运行并使用 Outlook 清单后),我会收到错误消息:

getAccessToken 错误:{"name":"身份验证中发生错误 来自 Office 的请求。","message":"发生意外错误 客户端。","代码":13006}

使用 Outlook,我发现有两个调用不是使用 Excel 进行的。

(1) https://outlook.office.com/owa/service.svc?action=GetAuthenticationUrl&app=Mail&n=104

响应:

ResultCode  0
WebSessionType  0
AuthenticationUrl    
"https://ccs.login.microsoftonline.com/ccs/common/oauth2/authorize?client_id=00000002-0000-0ff1-ce00-000000000000&redirect_uri=https%3a%2f%2foutlook.office.com%2fowa%2f&resource=00000002-0000-0ff1-ce00-000000000000&response_mode=form_post&response_type=code+id_token&scope=openid&msafed=1&msaredir=1&client-request-id=c75b3cd3-db77-0845-413d-d1890fe17698&protectedtoken=true&tokenenvelope=true&claims=%7b%22id_token%22%3a%7b%22xms_cc%22%3a%7b%22values%22%3a%5b%22CP1%22%5d%7d%7d%7d&nonce=637823342196948067.4c7773c4-3cd6-4e00-8bd9-ccd655dda53e&state=FcfBDYAwCEBR1DgOBguFdgH3qNCbN_dPxMNP3l8AYMvWbKFf-zWedybAlK0VZiln1y6N1A5xM2MXZA9FmUTY7ujoubVGjMrzAw"
ImplicitGrantAuthorizationUrl   ""

(2) https://outlook.office.com/owa/service.svc?action=GetAuthenticationUrl&app=Mail&n=104 login.microsoftonline.com/common/oauth2/authorize?.." rel="nofollow noreferrer">https://ccs.login.microsoftonline.com/common/oauth2/authorize?..。

响应:

404 Not Found

我不知道为什么 Excel 和 Outlook 的行为不同,除了可能是因为 设置

对于 Excel,有这样的

<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
  ....
    <WebApplicationInfo>
        <Id>123</Id>
        <Resource>api://localhost:3000/123</Resource>
        <Scopes>
            <Scope>openid</Scope>
            <Scope>profile</Scope>
            <Scope>access_as_user</Scope>
        </Scopes>
    </WebApplicationInfo>
  ....

:对于 Outlook,有这样的设置:

<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
  ....
    <WebApplicationInfo>
        <Id>123</Id>
        <Resource>api://localhost:3000/123</Resource>
        <Scopes>
            <Scope>openid</Scope>
            <Scope>profile</Scope>
            <Scope>access_as_user</Scope>
        </Scopes>
    </WebApplicationInfo>
  ....

I have created an add-in and Azure app similar to that shown in the Graph API/Add-in example docs - https://learn.microsoft.com/en-us/graph/tutorials/office-addin.

All is working well when the add-in runs in Excel (making sure the add-in can run in Excel and using an Excel manifest) and the call to OfficeRuntime.auth.getAccessToken returns the api token.

If I run the add-in in Outlook (after changing the add-in to run in Outlook and using an Outlook manifest) I get an error:

getAccessToken error: {"name":"Error occurred in the authentication
request from Office.","message":"An unexpected error occurred in the
client.","code":13006}

With Outlook I notice that two calls are made that aren't with Excel.

(1) https://outlook.office.com/owa/service.svc?action=GetAuthenticationUrl&app=Mail&n=104

Response:

ResultCode  0
WebSessionType  0
AuthenticationUrl    
"https://ccs.login.microsoftonline.com/ccs/common/oauth2/authorize?client_id=00000002-0000-0ff1-ce00-000000000000&redirect_uri=https%3a%2f%2foutlook.office.com%2fowa%2f&resource=00000002-0000-0ff1-ce00-000000000000&response_mode=form_post&response_type=code+id_token&scope=openid&msafed=1&msaredir=1&client-request-id=c75b3cd3-db77-0845-413d-d1890fe17698&protectedtoken=true&tokenenvelope=true&claims=%7b%22id_token%22%3a%7b%22xms_cc%22%3a%7b%22values%22%3a%5b%22CP1%22%5d%7d%7d%7d&nonce=637823342196948067.4c7773c4-3cd6-4e00-8bd9-ccd655dda53e&state=FcfBDYAwCEBR1DgOBguFdgH3qNCbN_dPxMNP3l8AYMvWbKFf-zWedybAlK0VZiln1y6N1A5xM2MXZA9FmUTY7ujoubVGjMrzAw"
ImplicitGrantAuthorizationUrl   ""

(2) https://ccs.login.microsoftonline.com/common/oauth2/authorize?...

Response:

404 Not Found

I don't know why Excel and Outlook are behaving differently except maybe because of the manifest setup.

For Excel there is this:

<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
  ....
    <WebApplicationInfo>
        <Id>123</Id>
        <Resource>api://localhost:3000/123</Resource>
        <Scopes>
            <Scope>openid</Scope>
            <Scope>profile</Scope>
            <Scope>access_as_user</Scope>
        </Scopes>
    </WebApplicationInfo>
  ....

For Outlook there is this:

<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
  ....
    <WebApplicationInfo>
        <Id>123</Id>
        <Resource>api://localhost:3000/123</Resource>
        <Scopes>
            <Scope>openid</Scope>
            <Scope>profile</Scope>
            <Scope>access_as_user</Scope>
        </Scopes>
    </WebApplicationInfo>
  ....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望她远 2025-01-19 12:11:30

要将 SSO 与 Outlook 加载项结合使用,您必须为 Microsoft 365 租赁启用新式身份验证。有关如何执行此操作的信息,请参阅 Exchange Online:如何为您的租户启用新式身份验证

要使用 SSO,您的 Outlook 加载项需要有一个向 Azure Active Directory (AAD) v2.0 注册的服务器端 Web API。有关详细信息,请参阅 注册一个通过 Azure AD v2.0 终结点使用 SSO 的 Office 加载项

请注意,新的单点登录 (SSO) 服务将取代 Office 网页版中使用的 Office 加载项的现有服务。这项新服务旨在提供更好的可靠性并支持使用 Office 网页版的其他环境。这仅适用于 Word、Excel 和 PowerPoint 的加载项。 Outlook 加载项不受此新服务推出的影响。阅读有关此内容的更多信息 在 Office 网页版中推出的 Office 加载项新单点登录服务文章。

最后,我建议从头开始为 Outlook 创建一个新的加载项,并检查它是否按预期工作。

To use SSO with an Outlook add-in, you must enable Modern Authentication for the Microsoft 365 tenancy. For information about how to do this, see Exchange Online: How to enable your tenant for modern authentication.

To use SSO, your Outlook add-in will need to have a server-side web API that is registered with Azure Active Directory (AAD) v2.0. For more information, see Register an Office Add-in that uses SSO with the Azure AD v2.0 endpoint.

Note, a new Single Sign-on (SSO) service will replace the existing one for Office Add-ins that are used in Office on the web. This new service is aimed at providing better reliability and supporting additional environments where Office on the web is used. This only applies to add-ins for Word, Excel, and PowerPoint. Outlook Add-ins are not impacted by this new service roll out. Read more about that in the New Single Sign-on service for Office Add-ins rolling out in Office on the web article.

Finally, I'd suggest creating a new add-in for Outlook from scratch and check whether it works as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文