Office 365 Mail API: Admin access token to access everyone's emails

让人想犯罪 __ 提交于 2019-12-12 02:59:37

问题


Is it possible for me to access everyone emails within my company using the Office 365 Mail API? I know I can access individuals, but hat requires me to be granted access to their emails and get their access tokens. I would like to be able to have an admin access token and be able to access everyone's emails. Any ideas whether this is possible or not?


回答1:


It is possible. We can register a Web application and/or Web API (default, known as a confidential client in OAuth2 parlance) an build a daemon service to retrieve all the messages for organization.

Here is an example that using the client credentials to request the token and get the messages from different users:

string authority = "https://login.microsoftonline.com/msdnofficedev.onmicrosoft.com";
        string resource = "https://Graph.microsoft.com";
        string clientID = "";
        string clientSecret = "";
        AuthenticationContext ac = new AuthenticationContext(authority);
        AuthenticationResult ar = ac.AcquireToken(resource, new ClientCredential(clientID, clientSecret));

        HttpClient hc = new HttpClient();
        hc.DefaultRequestHeaders.Add("Authorization", "Bearer " + ar.AccessToken);
        HttpResponseMessage hrm = await hc.GetAsync("https://Graph.microsoft.com/v1.0/users/fx@msdnofficedev.onmicrosoft.com/messages/");
        string content=await hrm.Content.ReadAsStringAsync();
        MessageBox.Show(content);

        HttpResponseMessage hrm2 = await hc.GetAsync("https://Graph.microsoft.com/v1.0/users/user1@msdnofficedev.onmicrosoft.com/messages/");
        content = await hrm2.Content.ReadAsStringAsync();
        MessageBox.Show(content);

For more detail about register application in Azure AD, you can follow link below: https://azure.microsoft.com/en-us/documentation/articles/active-directory-integrating-applications/#BKMK_Native



来源:https://stackoverflow.com/questions/36121571/office-365-mail-api-admin-access-token-to-access-everyones-emails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!