//public bool Do_OAuth(ref ExchangeService oService, ref string MailboxBeingAccessed, ref string AccountAccessingMailbox, // string sAuthority, string sAppId, string sRedirectURL, string sServername) //{ // bool bRet = false; // // See // https://msdn.microsoft.com/en-us/library/office/dn903761(v=exchg.150).aspx // // get authentication token // string authority = sAuthority; // string clientID = sAppId; // Uri clientAppUri = new Uri(sRedirectURL); // string serverName = sServername; // AuthenticationContext authenticationContext = new AuthenticationContext(authority, false); // PlatformParameters oPlatformParameters = new PlatformParameters(PromptBehavior.Always); // AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(serverName, clientID, clientAppUri, oPlatformParameters).Result; // //System.Diagnostics.Debug.WriteLine(authenticationResult.UserInfo.DisplayableId); // MailboxBeingAccessed = authenticationResult.UserInfo.DisplayableId; // AccountAccessingMailbox = authenticationResult.UserInfo.DisplayableId; // oAuth at this time does not support delegate or impersonation access - may need to change this in the future. // // Add authenticaiton token to requests // oService.Credentials = new OAuthCredentials(authenticationResult.AccessToken); // bRet = true; // return bRet; //} public ExchangeCredentials Do_OAuth(ref string MailboxBeingAccessed, ref string AccountAccessingMailbox, string sAuthority, string sAppId, string sRedirectURL, string sServername, ref string sBearerToken, PromptBehavior oPromptBehavior) { ExchangeCredentials oExchangeCredentials = null; // See // https://msdn.microsoft.com/en-us/library/office/dn903761(v=exchg.150).aspx // get authentication token string authority = sAuthority; string clientID = sAppId; Uri clientAppUri = new Uri(sRedirectURL); string serverName = sServername; AuthenticationContext authenticationContext = new AuthenticationContext(authority, false); PlatformParameters oPlatformParameters = new PlatformParameters(oPromptBehavior); AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(serverName, clientID, clientAppUri, oPlatformParameters).Result; sBearerToken = authenticationResult.AccessToken; // Add authenticaiton token to requests oExchangeCredentials = new OAuthCredentials(authenticationResult.AccessToken); MailboxBeingAccessed = authenticationResult.UserInfo.DisplayableId; AccountAccessingMailbox = authenticationResult.UserInfo.DisplayableId; // oAuth at this time does not support delegate or impersonation access - may need to change this in the future. return(oExchangeCredentials); }
public ClassBenchmark(string Mailbox, ExchangeCredentials Credentials, ClassStats Stats, ClassLogger Logger, string EWSUrl = "") { _service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate; _service.Credentials = Credentials; _mailbox = Mailbox; _stats = Stats; _logger = Logger; long startTicks = DateTime.Now.Ticks; if (!String.IsNullOrEmpty(EWSUrl)) { _logger.Log($"Using EWS URL: {EWSUrl}"); _service.Url = new Uri(EWSUrl); } else { _logger.Log(String.Format("Performing autodiscover for {0}", Mailbox)); try { _service.AutodiscoverUrl(Mailbox, AutodiscoverCallback); } catch (Exception ex) { _logger.Log(String.Format("Autodiscover failed: {0}", ex.Message)); } finally { long endTicks = DateTime.Now.Ticks; Stats.AddStat("Autodiscover", endTicks - startTicks); } } }
private ExchangeService CreateImpersonatedService(ImpersonatedUserId UserId, ExchangeCredentials exchangeCredentials) { return(new ExchangeService(this.exchangeVersion) { Credentials = exchangeCredentials, ImpersonatedUserId = UserId }); }
/// <summary> /// Manages Streaming Notifications for Exchange Users. Automatically assigns subscriptions to adequate CAS connections. /// </summary> /// <param name="credentials">Credentials with permission to impersonate the user mailboxes for all the subscriptions this instance will manage.</param> /// <param name="exchangeVersion">The version of the target Exchange server. Must be 2010 SP1 or higher</param> /// <param name="onNotificationEvent">The Action to invoke when Notifications arrive</param> public StreamingListener(ExchangeCredentials credentials, ExchangeVersion exchangeVersion, Action <SubscriptionNotificationEventCollection> onNotificationEvent) { _onNotificationEvent = onNotificationEvent; if ((int)exchangeVersion < 2) { throw new ArgumentException("ExchangeVersion must be 2010 SP1 or higher"); } _exchangeVersion = exchangeVersion; this._credentials = credentials; }
/// <summary><see cref="ExchangeClient"/> ctor.</summary> /// <param name="userConnection">An instance of the user connection.</param> /// <param name="emailCredentials">An instance of the user email credentials.</param> public ExchangeClient(UserConnection userConnection, EmailContract.DTO.Credentials emailCredentials) : this(userConnection) { _credentials = new ExchangeCredentials { UserName = emailCredentials.UserName, UserPassword = emailCredentials.Password, IsAutodiscover = emailCredentials.IsAutodiscover, ServerAddress = emailCredentials.ServiceUrl, UseOAuth = emailCredentials.UseOAuth }; ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; _ignoreSslWarnings = (bool)SysSettings.GetValue(userConnection, "IgnoreExchangeSSLWarnings", false); }
/// <summary><see cref="ExchangeClient"/> ctor.</summary> /// <param name="userConnection">An instance of the user connection.</param> /// <param name="credentials">An instance of the user credentials.</param> public ExchangeClient(UserConnection userConnection, Credentials credentials) : this(userConnection) { var mailServer = GetMailServer(credentials.ServerId); _credentials = new ExchangeCredentials { UserName = credentials.UserName, UserPassword = credentials.UserPassword, IsAutodiscover = mailServer.UseAutodiscover, ServerAddress = mailServer.ServerAddress, UseOAuth = credentials.UseOAuth }; ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; _ignoreSslWarnings = (bool)SysSettings.GetValue(userConnection, "IgnoreExchangeSSLWarnings", false); }
private void InitializeExchangeProxy(ExchangeCredentials credentials, Uri uri, long serverVersion) { Recorder.Trace(5L, TraceType.InfoTrace, new object[] { "ExchangeProxy.InitializeExchangeProxy Uri:", uri, "Version:", serverVersion, "Credentials:", credentials }); this.serverVersion = serverVersion; this.exchangeService = new ExchangeService(); this.exchangeService.Url = uri; this.exchangeService.Credentials = credentials; this.exchangeService.OnSerializeCustomSoapHeaders += new CustomXmlSerializationDelegate(this.OnSerializeCustomSoapHeaders); }
public ExchangeCredentials Do_OAuth(ref string MailboxBeingAccessed, ref string AccountAccessingMailbox, string sAuthority, string sAppId, string sRedirectURL, string sServername) { ExchangeCredentials oExchangeCredentials = null; // See // https://msdn.microsoft.com/en-us/library/office/dn903761%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396#bk_getToken // get authentication token string authority = sAuthority; string clientID = sAppId; Uri clientAppUri = new Uri(sRedirectURL); string serverName = sServername; AuthenticationContext authenticationContext = new AuthenticationContext(authority, false); AuthenticationResult authenticationResult = authenticationContext.AcquireToken(serverName, clientID, clientAppUri, PromptBehavior.Always); // Add authenticaiton token to requests oExchangeCredentials = new OAuthCredentials(authenticationResult.AccessToken); MailboxBeingAccessed = authenticationResult.UserInfo.DisplayableId; AccountAccessingMailbox = authenticationResult.UserInfo.DisplayableId; // oAuth at this time does not support delegate or impersonation access - may need to change this in the future. return(oExchangeCredentials); }
/// <summary> /// /// </summary> /// <param name="exchangeCredentials"></param> /// <param name="exchangeVersion"></param> public FolderChanges(ExchangeCredentials exchangeCredentials, ExchangeVersion exchangeVersion) : this(exchangeCredentials) { this.exchangeVersion = exchangeVersion; }
/// <summary> /// Initializes a new instance with specified Exchange credentials. Defaults to Exchange2010_SP1 Server version. /// </summary> /// <param name="exchangeCredentials">Credentials with permission to impersonate relevant user mailboxes</param> public FolderChanges(ExchangeCredentials exchangeCredentials) { this.exchangeCredentials = exchangeCredentials; }
/// <summary> /// Manages Streaming Notifications for Exchange Users. Automatically assigns subscriptions to adequate CAS connections. Exchange Version is assumed to be 2010_SP1 /// </summary> /// <param name="credentials">Credentials with permission to impersonate the user mailboxes for all the subscriptions this instance will manage.</param> /// <param name="onNotificationEvent">The Action to invoke when Notifications for any subscription arrive.</param> public StreamingListener(ExchangeCredentials credentials, Action <SubscriptionNotificationEventCollection> onNotificationEvent) { _onNotificationEvent = onNotificationEvent; _exchangeVersion = ExchangeVersion.Exchange2010_SP1; this._credentials = credentials; }
public ExchangeProxy(ExchangeCredentials credentials, Uri uri, long serverVersion) { this.InitializeExchangeProxy(credentials, uri, serverVersion); }