I have an EWS application for which I am supposed to implement oauth for accessing EWS managed APIs. I am trying to follow the code posted here: Authenticate an EWS application by using OAuth but not being able to figure out how to get the parameters like authority/clientId/clientAppUri and serverName. I have registered my app on azure portal but do not see any such info related to my app. Also, I am not able to see any permission saying "Access mailboxes as the signed-in user via Exchange Web Services" on azure management portal.
1 Answers
The question in that SO post references an MSDN article which has a section that explains what those values should be:
The Azure AD Authentication Library for .NET simplifies getting an authentication token from Azure Active Directory so that you can use the token in your application. You need to provide four pieces of information to get the token:
The URI of the token server. The token server is the authority that authenticates the user and returns a token that your application can use to access EWS.
The application client ID created when you registered your application with Azure Active Directory.
The application client URI created when you registered your application with Azure Active Directory.
The URI of the EWS server and the URI of the EWS endpoint. For Exchange as part of Office 365, this will be https:///ews/exchange.asmx.
The following code shows how to use the Azure AD Authentication Library to get an authentication token. It assumes that the information required to make the authentication request is stored in the application's App.config file
string authority = ConfigurationManager.AppSettings["authority"];
string clientID = ConfigurationManager.AppSettings["clientID"];
Uri clientAppUri = new Uri(ConfigurationManager.AppSettings["clientAppUri"];
string serverName = ConfigurationManager.AppSettings["serverName"];
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(serverName, clientId, clientAppUri);