Getting Microsoft Graph working

Last year we had to build a Cordova App and ship it on Windows Phones. It was a world of pain, and whilst I really think Microsoft are doing some great new stuff, some of their older stuff is not so great.

This week I've been working on importing mail from Office365 to a Laravel app. Again it was a world of pain and mystery. In the hope that I might save other devs some pain, here are a few of learning points:

  • There are two ways to authenticate Office 365 accounts, either via the Azure Portal or via the Application Registration Portal. All the documentation online makes it sound like these are pretty interchangeable, but I found that wasn't the case. If all you're doing is authentication, then it probably doesn't matter which you use, but once authenticated I needed to connect to the Microsoft Graph API and found that just wasn't possible with the Azure Portal method. If you're seeing errors like CompactToken parsing failed then you're probably need to be using the Application Registration Portal.
  • By default Microsoft doesn't include a refresh_token and the access_token expires about an hour after it is issued. If you need a refresh_token, within the scopes required you must request offline_access.
  • Once you're set up and authenticated with the Application Registration Portal method, then the Microsoft Graph SDK seems to work fine.

The main issue – which is often the case with Microsoft – is that they have cool new ways of doing things, but there is masses of documentation kick around for the old ways both on the Microsoft site and on forums.

Show Comments