This is part 2 of my MKR1000 article, in this previous post I looked at sending a Message via EWS using Basic Authentication. In this Post I'll look at using the new Outlook REST API which requires using OAuth authentication to get an Access Token.
The prerequisites for this sketch are the same as in the other post with the addition of the ArduinoJson library https://github.com/bblanchon/ArduinoJson which is used to parse the Authentication Results to extract the Access Token. Also the SSL certificates for the login.windows.net and outlook.office365.com need to be uploaded to the devices using the wifi101 Firmware updater.
To use Token Authentication you need to register an Application in Azure https://msdn.microsoft.com/en-us/office/office365/howto/add-common-consent-manually with the Mail.Send permission. The application should be a Native Client app that use the Out of Band Callback urn:ietf:wg:oauth:2.0:oob. You need to authorize it in you tenant (eg build a small app that can do that which will prompt for authorization). One that is done you then need to set that ClientId variable in the sketch
String ClientId = "8fe353d6-efa0-4b0f-aafb-ab7cf3a9b307";
I've put a copy of this Sketch up https://github.com/gscales/Arduino-MRK1000/blob/master/REST-Office365SendSample.ino the code looks like