Office365 API: OAuth2 AccessTokens for app-only require that the

236 views Asked by At

I'm creating a subscription request to Outlook Push Notification using this URL :

https://outlook.office365.com/api/v2.0/me/subscriptions

I have used certificate based authentication with Azure AD to acquire token using the following code:

AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/mytenant/oauth2/v2.0/token");
AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://outlook.office365.com/", certificate);

When calling the subscription API I'm getting a Forbidden error with the following response:

x-ms-diagnostics: 2000008;reason="OAuth2 AccessTokens for app-only require that the target mailbox is explicitly specified with the api call";error_category="invalid_grant"

Could you please help me with where I'm going wrong or how to debug / solve this error.

Thanks in advance

1

There are 1 answers

0
Yogesh On

Since you are using App-only tokens you are required by the API to explicitly specify the target mailbox in the URI. Eg: https://outlook.office365.com/api/v2.0/Users([email protected])/subscriptions

me is only useful in case the target mailbox is same as authenticated user. However in case of app-only there is no authenticated user, do you have to be explicit.