以Admin身份访问所有用户驱动器

时间:2017-11-14 15:37:42

标签: microsoft-graph onedrive

我正在构建一个使用Microsoft Graph的本机应用程序。 我想通过管理员帐户阅读组织中所有用户的OneDrive中的所有文件。

我正在使用(Azure AD 2.0)OAUTH授权工作流来获取授权代码。之后我获得访问令牌和刷新令牌。

但是,当我尝试访问任何用户的驱动器时:

graphClient.Drives["amit@csys.onmicrosoft.com"].Root.Request().GetAsync();
// where graphClient is instance of GraphServiceClient

我明白了:

  

generalException

     

消息:服务返回意外异常。

使用调用堆栈:

  at Microsoft.Graph.HttpProvider.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Graph.BaseRequest.<SendAsync>d__32`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Graph.DriveItemRequest.<GetAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OneDrive_Writer.OneDriveWriter.<loadRootDriveFolder>d__9d.MoveNext()

管理员是否可以访问所有其他用户的驱动器文件?

注意:当我以管理员身份登录时,我可以访问管理员的OneDrive帐户。

1 个答案:

答案 0 :(得分:1)

示例中的Drives索引器需要driveId,而不是upn。

假设您的权限已正确设置,并且您拥有有效的访问令牌, 你会做这样的事情。

// Access the users in the org.
var users = await graphClient.Users.Request().GetAsync();

// Get the drives for a user.
var drives = await graphClient.Users[users[0].Id].Drives.Request().GetAsync();

// Get the specific drive metadata for a user
var drive = await graphClient.Drives[drives[0].Id].Request().GetASync();