Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

EWS API authentication using OAuth (401: UnAuthorized)

$
0
0

Hi,

I am unable to access mailbox of a user, using OAuth.

I followed this article How to: Authenticate an EWS application by using OAuth

I am able to generate a token using 'AuthenticationContext.AcquireTokenAsync()', but then getting 401 error 'UnAuthorized.

Here is my code to generate OAuth token:

public  async Task<string> AcquireTokenAsyncForApplication(string clientId, string clientSecret, string tenantName)
        {
            var ResourceUrl = "https://outlook.office365.com";
            var AuthString = "https://login.microsoftonline.com/" + tenantName;// 
            if (TokenForApplication == null)
            {                
                AuthenticationContext authenticationContext = new AuthenticationContext(AuthString, false);              
                ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
                AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, clientCred);// 
                TokenForApplication = authenticationResult.AccessToken;
            }
            return TokenForApplication;
        }

I have registered the app properly, with permission 'Using Exchange Web Services with full access to all mailboxes'

Note: I am using Azure ADAL Lib 3.17.0, so using AcquireTokenAsync() instead of 'AcquireToken()'. I also, dont want to get a pop up, to enter user credentials, instead have to use ClientID (ApplicationID) + ClientSecret(Key).

Regards,

 


Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>