简体   繁体   English

Office365 API - 访问其他用户/房间的日历

[英]Office365 API - Accessing another users/room's calendars

I'm attempting to build an application that will have access to all of an organization's calendars (users, rooms, etc). 我正在尝试构建一个可以访问组织的所有日历(用户,房间等)的应用程序。

Currently my auth flow will sign in on behalf of a tenant user and make use of refresh tokens to access needed resources. 目前,我的身份验证流程将代表租户用户登录,并使用刷新令牌来访问所需的资源。 As soon as I make a request to: 我一提出要求:

https://outlook.office365.com/api/v1.0/users/{room-resource@email}/events

My application is responded with a 401 我的应用程序以401响应

From my gathering, it seems that this flow is limited to a single user's scope. 从我的收集来看,似乎这个流程仅限于单个用户的范围。 Although the tenant admin should have permission to see any of the room resources, the room is technically a user itself so the API will respond with a forbidden error. 虽然租户管理员应该有权查看任何房间资源,但该房间在技术上是用户本身,因此API将以禁止的错误进行响应。 It now seems that the proper flow is a tenant admin must grant permission to my application using the new Service OAuth Flow . 现在似乎正确的流程是租户管理员必须使用新的服务OAuth流授予我的应用程序权限。

Reading through this post it seems that the API is making use of OAuth client credentials grant type (app only tokens). 通过阅读这篇文章,似乎API正在使用OAuth 客户端凭据授权类型 (仅限应用程序令牌)。 Instead of using the /oauth/common endpoint I now have to use /oauth/tenant-id which I can retrieve via the JWT token returned in the code+id_token response type. 我现在必须使用/oauth/tenant-id而不是使用/oauth/common端点,我可以通过code+id_token响应类型中返回的JWT令牌来检索。 This leads to my first question: 这导致了我的第一个问题:

Is using the OpenID flow the only way to initially retrieve the tenant ID? 使用OpenID流程是最初检索租户ID的唯一方法吗?

Next is where things get a little fuzzy for me. 接下来是对我来说有点模糊的地方。

We now have to generate an X.509 SSL certificate and upload the fingerprint/value to our Azure application manifest. 我们现在必须生成X.509 SSL证书并将指纹/值上传到我们的Azure应用程序清单。 Easy enough. 很容易。

Then according to the discussion in Office 365 Rest API - Daemon week authentication we build a specific JWT, base64 encode it, and sign it with our cert. 然后根据Office 365 Rest API中的讨论- 守护进程周认证,我们构建一个特定的JWT,base64对其进行编码,并使用我们的证书进行签名。

I haven't actually gotten to the last few steps here but I will post my results when I can. 我实际上没有完成最后几步,但我会在可以的时候发布我的结果。 I'm just making sure that I seem to be following the correct procedure for what resources I'm trying to access. 我只是确保我似乎正在遵循正在尝试访问的资源的正确程序。 I know the service tokens are a fairly new feature, it's just unfortunate that I had to find the flow of sending the signed JWT on Stackoverflow rather than official MSFT documentation... 我知道服务令牌是一个相当新的功能,不幸的是我必须找到在Stackoverflow上发送已签名的JWT的流程,而不是官方的MSFT文档......

I also noticed that since we're using the client credentials flow we will not receive a refresh_token in the response. 我还注意到,由于我们正在使用客户端凭据流,因此我们不会在响应中收到refresh_token So for my final question: 对于我的最后一个问题:

When accessing different resources (ie Graph API/Office365 API) do I just get a different access token for each resource using my signed request instead of using refresh tokens for multiple resources ? 当访问不同的资源(即Graph API / Office365 API)时,我是否只使用签名请求为每个资源获取不同的访问令牌,而不是使用刷新令牌来获取多个资源

If the general direction I seem to be going is correct let me know! 如果我似乎正在进行的总体方向是正确的,请告诉我! Any help is greatly appreciated. 任何帮助是极大的赞赏。

Late to the party, but I've been fighting thru this too, and here's what I've found. 晚了,但我也一直在争吵,这就是我发现的。

The OAuth route into Office365 will only allow you to access your own calendar. 进入Office365的OAuth路由只允许您访问自己的日历。 Doesn't matter what permissions the app has in Azure, or what you configure per user. 无论应用程序在Azure中具有哪些权限,或每个用户配置的权限。 It's a limitation to the API. 这是API的限制。

This was confirmed by MSFT in the comments to this StackOverflow question: MSFT在对StackOverflow问题的评论中证实了这一点:
Office365 API - Admin accessing another users/room's calendar events Office365 API - 管理员访问其他用户/房间的日历活动

You can, however, use Basic Auth to gain access to another person's calendar. 但是,您可以使用Basic Auth访问其他人的日历。

1) Configure the "Primary" user (the one you authenticate with) to have access to the "Secondary" user's (the one with the calendar you want to view) account. 1)配置“主要”用户(您通过身份验证的用户)可以访问“辅助”用户(具有您要查看的日历的用户)帐户。 To do this, go in to the Exchange Properties for the Secondary user -> Mailbox Delegation and give Full Access to the Primary User. 为此,请转到辅助用户的Exchange属性 - >邮箱委派,并授予主用户完全访问权限。

2) Pass the authentication along with the request to the Office365 API: 2)将身份验证和请求一起传递给Office365 API:

<?php
$username = 'primary@user.com';
$password = 'mypass';
$URL = 'https://outlook.office365.com/api/v1.0/users/secondary@user.com/events';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result=curl_exec ($ch);
curl_close ($ch);

print_r($result);

?>

3) If you've done everything right, you now have the events for the Secondary user! 3)如果你已经做好了一切,你现在可以为次要用户做事了!

You are following the right path. 你正在走正确的道路。 You will need one token per resource, which will grant you access to all users. 每个资源需要一个令牌,这将授予您对所有用户的访问权限。 When that token expires, you will just request a new one. 当该令牌到期时,您将只需要一个新令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM