Authentication Problems Using the Office 365 API

2019-02-14 14:30发布

问题:

My goal is to get the user's (Office 365 and Outlook.com) meetings for a given day in a WPF C# project. Following the steps described in the Outlook Dev Center Tutorial, the second step (after registering the app) would be to authenticate the user using OAuth2. But I cannot make it work:

  • I did not find any tutorial/code snippet which I was able to run. They are all written either for Apps or Asp.Net (or something else). I tried to adapt these, but without success...
  • I installed the Active Directory Authentication Library (ADAL) and Microsoft Office 365 Mail, Calendar and Contacts Library via Nuget.
  • I also don't want to use an Azure subscription, just to read some meetings. And I think it's also not necessary for my purpose as they say it's only important for advanced management.
  • When I try to obtain a token with the credentials which I got from the Application Registration Portal, I get: Application '<id>' is not supported for this API version.. Looking the error up on StackOverflow tells me to register the application, which is what I did.
  • When I try to obtain a token with the credentials from the Office App Registration Portal, I get: Application with identifier '<id>' was not found in the directory outlook.office365.com.
  • Documentation is really confusing to me, with many different APIs (Graph API, 365 API, etc.) and many dead pages in the documentation...

I'd really appreciate any pointers towards my goal.

回答1:

If you want to be able to get items from Outlook.com as well as O365 outlook, you should use the new v2.0 app model. You will find useful documentation here : https://azure.microsoft.com/en-us/documentation/articles/active-directory-v2-app-registration/

You should read the limitations here: http://azure.microsoft.com/documentation/articles/active-directory-v2-limitations/

While you can use any Microsoft account to register applications, not all Microsoft accounts have been enabled for the REST APIs. To request an Outlook.com developer preview account with the REST APIs enabled, send an email at outlookdev@microsoft.com

Finally if you want a sample to log in within a desktop application, check this tutorial : https://azure.microsoft.com/en-us/documentation/articles/active-directory-v2-devquickstarts-wpf/