Geeting server reference in Exchange online

-- -- 882 Reputation points
2021-04-01T19:11:49.553+00:00

Hi

I am just starting out with OAuth authentication for Exchange online. I have tried below code from here to get reference to exchange service;

        Dim pcaOptions = New PublicClientApplicationOptions With {  
        .ClientId = "00000000-0000-0000-0000-000000000000",  
        .TenantId = "00000000-0000-0000-0000-000000000000"  
        }  
  
        Dim pca = PublicClientApplicationBuilder.CreateWithApplicationOptions(pcaOptions).Build()  
        Dim ewsScopes = New String() {"https://outlook.office365.com/EWS.AccessAsUser.All"}  
  
        Dim authResult = pca.AcquireTokenInteractive(ewsScopes).ExecuteAsync()  
        Dim ewsClient = New ExchangeService()  
          
        ewsClient.Url = New Uri("https://outlook.office365.com/EWS/Exchange.asmx")  
        ewsClient.Credentials = New OAuthCredentials(authResult.Result.AccessToken)  

My code was getting stuck indefinitely at;

Dim authResult = pca.AcquireTokenInteractive(ewsScopes).ExecuteAsync()  

I changed it to below and it went ahead.

 Dim authResult = pca.AcquireTokenInteractive(ewsScopes).**WithUseEmbeddedWebView(True)**.ExecuteAsync()  

Now it is indefinitely stuck at;

ewsClient.Credentials = New OAuthCredentials(authResult.Result.AccessToken)  

What am I doing wrong and how can I get the exchange service reference?

Thanks

Regards

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
522 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Glen Scales 4,431 Reputation points
    2021-04-06T00:09:42.747+00:00

    AcquireTokenInteractive should pop up an dialog (or embedded/system browser) where the authentication will take place (or a consent will popup if you app hasn't been consented to). Are you seeing the browser auth happening ? what client are you using ?