// Token: 0x0600059B RID: 1435 RVA: 0x0002B16C File Offset: 0x0002936C public static Uri DiscoverCloudArchiveEwsUrl(ADUser user) { Uri result = null; string text = null; string domain = user.ArchiveDomain.Domain; Uri uri = null; EndPointDiscoveryInfo endPointDiscoveryInfo; bool flag = RemoteDiscoveryEndPoint.TryGetDiscoveryEndPoint(OrganizationId.ForestWideOrgId, domain, null, null, null, out uri, out endPointDiscoveryInfo); if (endPointDiscoveryInfo != null && endPointDiscoveryInfo.Status != EndPointDiscoveryInfo.DiscoveryStatus.Success) { ElcEwsClientHelper.Tracer.TraceDebug <SmtpAddress, EndPointDiscoveryInfo.DiscoveryStatus, string>(0L, "Getting autodiscover url for {0} encountered problem with status {1}. {2}", user.PrimarySmtpAddress, endPointDiscoveryInfo.Status, endPointDiscoveryInfo.Message); } if (!flag || uri == null) { ElcEwsClientHelper.Tracer.TraceError <SmtpAddress>(0L, "Failed to get autodiscover URL for {0}.", user.PrimarySmtpAddress); return(null); } SmtpAddress archiveAddress = new SmtpAddress(SmtpProxyAddress.EncapsulateExchangeGuid(domain, user.ArchiveGuid)); Guid value = Guid.NewGuid(); OAuthCredentials oauthCredentialsForAppActAsToken = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(OrganizationId.ForestWideOrgId, user, domain); oauthCredentialsForAppActAsToken.ClientRequestId = new Guid?(value); AutodiscoverService service = new AutodiscoverService(EwsWsSecurityUrl.FixForAnonymous(uri), 4) { Credentials = new OAuthCredentials(oauthCredentialsForAppActAsToken), PreAuthenticate = true, UserAgent = ElcEwsClientHelper.GetOAuthUserAgent("ElcAutoDiscoverClient") }; service.ClientRequestId = value.ToString(); service.ReturnClientRequestId = true; try { ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Combine(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback(ElcEwsClientHelper.CertificateErrorHandler)); GetUserSettingsResponse response = null; Exception arg = null; bool flag2 = ElcEwsClientHelper.ExecuteEwsCall(delegate { response = service.GetUserSettings(archiveAddress.ToString(), new UserSettingName[] { 58 }); }, out arg); if (flag2) { if (response.ErrorCode == null) { if (!response.TryGetSettingValue <string>(58, ref text) || string.IsNullOrEmpty(text)) { ElcEwsClientHelper.Tracer.TraceError <SmtpAddress, SmtpAddress>(0L, "Sucessfully called autodiscover, but did not retrieve a url for {0}/{1}.", user.PrimarySmtpAddress, archiveAddress); } } else { ElcEwsClientHelper.Tracer.TraceError(0L, "Unable to autodiscover EWS endpoint for {0}/{1}, error code: {2}, message {3}.", new object[] { user.PrimarySmtpAddress, archiveAddress, response.ErrorCode, response.ErrorMessage }); } } else { ElcEwsClientHelper.Tracer.TraceError <SmtpAddress, SmtpAddress, Exception>(0L, "Unable to autodiscover EWS endpoint for {0}/{1}, exception {2}.", user.PrimarySmtpAddress, archiveAddress, arg); } } finally { ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Remove(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback(ElcEwsClientHelper.CertificateErrorHandler)); } if (!string.IsNullOrEmpty(text)) { result = new Uri(text); } return(result); }