gpt4 book ai didi

outlook-addin - 从 Outlook Web 加载项访问 Outlook Rest API

转载 作者:行者123 更新时间:2023-12-04 07:29:35 30 4
gpt4 key购买 nike

我开发了一个运行良好的 Outlook Web 插件。它是一个任务 Pane ,可在约会的组合模式下使用,它收集事件数据、添加一些数据并将其发送到某个地方的 API。

我现在想做的是将经过身份验证的用户订阅到 Outlook Rest API,以便在事件被删除时得到通知。

订阅调用应如下所示:

POST https://outlook.office.com/api/v2.0/me/subscriptions HTTP/1.1 
Content-Type: application/json
{
@odata.type:"#Microsoft.OutlookServices.PushSubscription",
Resource: "https://outlook.office.com/api/v2.0/me/events",
NotificationURL: "https://myNotifAPI.azurewebsites.net/api/send/myNotifyClient",
ChangeType: "Deleted",
ClientState: "blabla"
}

我知道在发布到订阅 URL 时我需要提供有效的身份验证承载 token ,因此我尝试在加载项中调用此方法:
_mailbox = Office.context.mailbox;
_mailbox.getUserIdentityTokenAsync(getUserIdentityTokenCallback);

在函数中 getUserIdentityTokenAsync ,我调用一个 WebApi Controller 来验证我的 token 并将其发送回加载项:
AppIdentityToken token = (AppIdentityToken)AuthToken.Parse(rawToken);
token.Validate(new Uri(request.AudienceUrl));
return token;

我尝试使用该 token 发布到 https://outlook.office.com/api/v2.0/me/subscriptions (使用 postman )但我收到 401 说:
reason="The audience claim value is invalid '<MyAddInURL>'.";error_category="invalid_resource"

在这种特殊情况下使用它是正确的 token 还是我需要获得另一个 token ?任何建议将不胜感激!

-- 编辑 --

正如@benoit-patra 所建议的,我尝试使用 getCallbackTokenAsync 获取 token 而不是 getUserIdentityTokenAsync但是当我调用 https://outlook.office.com/api/v2.0/me/subscriptions我确实收到了 403 :
"error": {
"code": "ErrorAccessDenied",
"message": "The api you are trying to access does not support item scoped OAuth."
}

根据@benoit-patra 的要求,这里是 token 内容:
{
"nameid": "9d643d8c-b301-4fe1-83f7-bf41b1749379@57bcd3d9-685a-4c41-8c7d-xxxxxx",
"ver": "Exchange.Callback.V1",
"appctxsender": "https://localhost:44444/NewAppointment.html@57bcd3d9-685a-4c41-8c7d-xxxxxx",
"appctx": {
"oid": "3a8a4f92-a010-40bd-a093-xxxxxx",
"puid": "10033FFF9xxxxx",
"smtp": "max@xxxx.onmicrosoft.com",
"upn": "max@xxxx.onmicrosoft.com",
"scope": "ParentItemId:AAMkADE4NTk2MDNjLTI4NGEtNDZkNS1hMzg4LTE3MzI2NGJhZWRkZQBGAAAAAAD+YYA7CnMtRZsrwJ7l6m44BwCcSer9F+cXSrWNauuHQlZ7AAAAAAENAACcSer9F+cXSrWNaxxxxxxxx"
},
"iss": "00000002-0000-0ff1-ce00-000000000000@57bcd3d9-685a-4c41-8c7d-xxxxx",
"aud": "00000002-0000-0ff1-ce00-000000000000/outlook.office365.com@57bcd3d9-685a-4c41-8c7d-xxxx",
"exp": 1487087672,
"nbf": 1487087372
}

最佳答案

上一个答案是正确的,错误是因为您正在获取一个项目范围的 token 。因为以前回调 token 只允许调用者调用 GetItemGetItemAttachment REST API。我们正在对回调 token 进行更改,以便客户端也可以调用 API 的 REST。要求首先你应该有readWriteMailBox允许。其次通过提供 isRest=true 获取 REST 回调 token ,像下面

Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function (result))

生成的 token 将具有 Mail.ReadWrite , Calendar.ReadWrite , Contacts.ReadWrite , 和 Mail.Send范围。

那就是 isRest目前仅 Outlook 移动客户端支持该参数。在 OWA 和 Outlook 上支持它的工作正在进行中,我们预计将在 3 月份发布。

关于outlook-addin - 从 Outlook Web 加载项访问 Outlook Rest API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42222773/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com