I'm trying to use beta version of MS Outlook Mail REST with app-only tokens but the requests doesn't work as expected.
For example, folder hierarchy synchronization behaves like v2.0 and doesn't work with app-only tokens.
I'm trying to use beta version of MS Outlook Mail REST with app-only tokens but the requests doesn't work as expected.
For example, folder hierarchy synchronization behaves like v2.0 and doesn't work with app-only tokens.
The app-only token works well for this request. What's the error you get?
To call this request with app-only token, we need to specific user instead of me in the document like request below:
GET https://outlook.office365.com/api/v2.0/users/userPrincipalName/MailFolders
And to get the app-token, I use the code below:
public static async Task<string> GetTokenByCert(string clientId, string tenant, string certThumbprint,string resource)
{
string authority = $"https://login.windows.net/{tenant}";
X509Certificate2 cert = CertHelper.FindCert(certThumbprint);
var certCred = new ClientAssertionCertificate(clientId, cert);
var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authority);
AuthenticationResult result = null;
try
{
result = await authContext.AcquireTokenAsync(resource, certCred);
}
catch (Exception ex)
{
}
return result.AccessToken;
}