I'm trying to access the Office365 REST API using the ADAL library but get a 401 (Unauthorized), and can't figure out why. I have registered an application in our Azure AD, got an id, fetched a key for it and given it permissions to read the Windows Azure Active Directory.
I am able to acquire an OAuth token but it won't play with the Office365 API.
Here is one of my unsuccessful attempts:
AuthenticationContext auth = new AuthenticationContext("https://login.windows.net/" + myTenant); AuthenticationResult authenticationResult = auth.AcquireToken("http://Rest", new ClientCredential(myId, myKey)); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken); HttpResponseMessage msg = await client.GetAsync("https://outlook.office365.com/api/v1.0/me/events"); // => Bam. 401. :( Any ideas?