[今天,我们有一个将约会同步到Exchange的应用程序。我们有多个客户使用不同版本的Exchange,例如:Exchange 2010,o365。每个客户都创建了一个具有模拟权限的服务帐户,我们将其用于身份验证。一个例子:
var credentials = new WebCredentials(serviceAccount.username, serviceAccount.password);
var service = new ExchangeService
{
Credentials = credentials,
Url = new Uri(exchangeUri)
}
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, email);
因此,此方法从2020年10月13日起将不再起作用,我们将不得不使用OAuth。我已经阅读了MS文档“使用OAuth验证EWS应用程序”:https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth
我已经在Azure AD中注册了我的应用程序,并获得了一个应用程序ID。我想我应该使用“应用程序权限”,并通过以下代码来获取令牌:
// Configure the MSAL client to get tokens
var app = ConfidentialClientApplicationBuilder
.Create(ConfigurationManager.AppSettings["appId"])
.WithAuthority(AzureCloudInstance.AzurePublic, ConfigurationManager.AppSettings["tenantId"])
.WithClientSecret(ConfigurationManager.AppSettings["clientSecret"]).Build();
// The permission scope required for EWS access
var ewsScopes = new string[] { "https://outlook.office.com/.default" };
//Make the toekn request
AuthenticationResult authResult = await app.AcquireTokenForClient(ewsScopes).ExecuteAsync();
我的问题:
非常感谢您的帮助/建议。