Accessing OneNote via Graph API

233 views Asked by At

I have an MS account (not 365) which gives me access to the office suite online. My OneNote files are stored in OneDrive. I also have an Azure account with a registered app. Although both of these accounts have the same credentials, it looks like they're not connected. When I authenticate via my Azure app the token I get does not give me access to OneDrive or OneNote. I CAN access everything via graph explorer. When I copy and paste the token generated in explorer into my code, the code works perfectly. I cannot figure out how to connect my MS Office account with my Azure account.

I know it's possible to access my data via Graph because it works in explorer. When I try and access https://graph.microsoft.com/v1.0/me/onenote/notebooks I get 404: Not Found. I believe this is because there is no data in my Azure account. How do I connect them? Thank you.

1

There are 1 answers

1
Allen Wu On BEST ANSWER

Based on your description, I believe that you are trying to access your OneNote under MS account.

Please see OAuth 2.0 and OpenID Connect protocols Endpoints.

Once registered, the app communicates with Microsoft identity platform by sending requests to the endpoint:

https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token

Let's focus on {tenant}.

enter image description here

If you specify a particular tenant id here, the access token is used for AAD account only in this tenant.

If you want to get an access token for your MS account, you should specify {tenant} as common or consumers. I suggest that you use common here. And you need to register the Azure AD application like this:

enter image description here

Graph Explorer also uses common endpoint. That is why you can access to OneNote of the MS account.