private static ICredentials GetActAsUserCredentials(ADUser user) { ICredentials oauthCredentialsForAppActAsToken = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(user.OrganizationId, user, null); AADClientFactory.Tracer.TraceDebug <string, ICredentials>(0L, "Created user credentials for {0}: {1}", user.UserPrincipalName, oauthCredentialsForAppActAsToken); return(oauthCredentialsForAppActAsToken); }
public ICredentials GetCredentials(IConfigurationSession configurationSession, ADUser actAsUser = null) { ArgumentValidator.ThrowIfNull("configurationSession", configurationSession); ICredentials credentials = null; string organizationIdKey = this.GetOrganizationIdKey(configurationSession); if (!string.IsNullOrEmpty(organizationIdKey)) { string stringFromConfigFile = this.GetStringFromConfigFile("UP_TenantAdminCred_" + organizationIdKey); int num = stringFromConfigFile.IndexOf(':'); if (num > 0) { credentials = new NetworkCredential(stringFromConfigFile.Substring(0, num), stringFromConfigFile.Substring(num + 1)); } } if (credentials == null) { Organization orgContainer = configurationSession.GetOrgContainer(); if (orgContainer != null && orgContainer.OrganizationId != null) { if (actAsUser != null) { credentials = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(orgContainer.OrganizationId, actAsUser, null); } else { credentials = OAuthCredentials.GetOAuthCredentialsForAppToken(orgContainer.OrganizationId, "PlaceHolder"); } } } return(credentials); }
// Token: 0x06000564 RID: 1380 RVA: 0x00029528 File Offset: 0x00027728 public override ExchangeServiceBinding CreateServiceBinding(Uri serviceUrl) { Tracer.TraceInformation("ElcEwsCallingContext.CreateServiceBinding", new object[0]); ExchangeServiceBinding exchangeServiceBinding = base.CreateServiceBinding(serviceUrl); if (this.isCrossPremise) { OAuthCredentials oauthCredentialsForAppActAsToken = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(this.user.OrganizationId, this.user, this.user.ArchiveDomain.Domain); exchangeServiceBinding.UseDefaultCredentials = false; exchangeServiceBinding.Credentials = oauthCredentialsForAppActAsToken; exchangeServiceBinding.UserAgent = this.userAgent; exchangeServiceBinding.ManagementRole = new ManagementRoleType { ApplicationRoles = new string[] { "UserApplication" } }; } else { exchangeServiceBinding.UseDefaultCredentials = true; exchangeServiceBinding.Disposed += delegate(object param0, EventArgs param1) { ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Remove(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback(ElcEwsCallingContext.CertificateErrorHandler)); }; ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Combine(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback(ElcEwsCallingContext.CertificateErrorHandler)); } return(exchangeServiceBinding); }
private OAuthCredentials GetOAuthCredentials() { ADUser accessingADUser = this.currentCallContext.AccessingADUser; if (accessingADUser == null) { this.LogError("[GetInlineExploreSpContent.GetOAuthCredentials()]:OAuth error", "AccessingADUser is null"); return(null); } return(OAuthCredentials.GetOAuthCredentialsForAppActAsToken(accessingADUser.OrganizationId, accessingADUser, null)); }
public static IAuthenticator Create(OrganizationId organizationId, ADObjectId executingUserId) { ArgumentValidator.ThrowIfNull("organizationId", organizationId); ArgumentValidator.ThrowIfNull("executingUserId", executingUserId); ADSessionSettings sessionSettings = ADSessionSettings.FromExternalDirectoryOrganizationId(new Guid(organizationId.ToExternalDirectoryOrganizationId())); IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 54, "Create", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\EOPRecipient\\Authenticator.cs"); ADUser actAsUser = tenantOrRootOrgRecipientSession.FindADUserByObjectId(executingUserId); OAuthCredentials oauthCredentialsForAppActAsToken = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(organizationId, actAsUser, null); return(new Authenticator(oauthCredentialsForAppActAsToken)); }
public static OAuthCredentials Create(InternalClientContext clientContext, RequestLogger requestLogger) { ArgumentValidator.ThrowIfNull("clientContext", clientContext); OrganizationId organizationId = clientContext.OrganizationId; ADUser aduser = clientContext.ADUser; string text = FaultInjection.TraceTest <string>((FaultInjection.LIDs) 2743479613U); if (!string.IsNullOrEmpty(text)) { SmtpAddress smtpAddress = SmtpAddress.Parse(text); IRecipientSession recipientSession = DirectorySessionFactory.Default.CreateTenantRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromTenantAcceptedDomain(smtpAddress.Domain), 68, "Create", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\RequestDispatch\\OAuthCredentialsFactory.cs"); aduser = (recipientSession.FindByProxyAddress(ProxyAddress.Parse(text)) as ADUser); organizationId = aduser.OrganizationId; } OAuthCredentials oauthCredentialsForAppActAsToken = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(organizationId, aduser, null); OAuthCredentialsFactory.SetCredentialsProperties(oauthCredentialsForAppActAsToken, clientContext, requestLogger); return(oauthCredentialsForAppActAsToken); }
internal static OAuthCredentials GetOAuthCredential(string sipUri) { ProxyAddress proxyAddress = ProxyAddress.Parse(sipUri); string sipDomain = OnlineMeetingHelper.GetSipDomain(sipUri); if (string.IsNullOrEmpty(sipDomain)) { ExTraceGlobals.OnlineMeetingTracer.TraceError <string>(0L, "[UcwaConfigurationUtilities.GetOAuthCredential] Unable to determine domain from sip uri: {0}", sipUri); throw new OwaException(string.Format("Unable to determine domain from sip uri: {0}", sipUri)); } MiniRecipient miniRecipient = null; IRecipientSession recipientSession = null; try { recipientSession = UserContextUtilities.CreateScopedRecipientSession(true, ConsistencyMode.FullyConsistent, sipDomain, null); } catch (OwaADObjectNotFoundException innerException) { throw new OwaException(string.Format("Couldn't create a scoped recipient session for {0}", sipDomain), innerException); } try { miniRecipient = recipientSession.FindByProxyAddress <MiniRecipient>(proxyAddress); if (miniRecipient == null) { ExTraceGlobals.OnlineMeetingTracer.TraceError <string>(0L, "[UcwaConfigurationUtilities.GetOAuthCredential] IRecipientSession.FindByProxyAddress() unable to find to recipient with address: {0}", sipUri); throw new OwaException(string.Format("Couldn't find a match for {0}", proxyAddress.ToString())); } } catch (NonUniqueRecipientException innerException2) { ExTraceGlobals.OnlineMeetingTracer.TraceError <string>(0L, "[UcwaConfigurationUtilities.GetOAuthCredential] Couldn't find a unique match for: {0}", sipUri); throw new OwaException(string.Format("Couldn't find a unique match for {0}", proxyAddress.ToString()), innerException2); } return(OAuthCredentials.GetOAuthCredentialsForAppActAsToken(miniRecipient.OrganizationId, miniRecipient, sipDomain)); }
internal static ICredentials GetICredentials(bool appOnly, ADUser user, string domain) { ICredentials result; if (appOnly) { OrganizationId organizationId = OrganizationId.FromAcceptedDomain(domain); result = OAuthCredentials.GetOAuthCredentialsForAppToken(organizationId, domain); } else { if (user == null) { throw new Exception(Strings.NullUserError); } OrganizationId organizationId = user.OrganizationId; if (organizationId == null) { throw new Exception(Strings.NullOrgIdException(user.Name)); } result = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(organizationId, user, domain); } return(result); }
internal static ICredentials GetCredentialAndConfigureClientContext(ADRawEntry actAsUser, OrganizationId actAsUserOrgId, ClientContext context, bool createAppTokenOnly, out bool isOAuthCredential) { if (!createAppTokenOnly && actAsUser == null) { throw new ArgumentNullException("actAsUser"); } if (actAsUserOrgId == null) { throw new ArgumentNullException("actAsUserOrgId"); } int num = 0; isOAuthCredential = true; RegistryKey registryKey = null; try { registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchangeRPC\\ParametersSystem", RegistryKeyPermissionCheck.ReadSubTree); if (registryKey != null) { num = (int)registryKey.GetValue("TMPublishHttpDebugEnabled", 0); if ((int)registryKey.GetValue("TMOAuthEnabled", 1) == 0) { isOAuthCredential = false; return(null); } } } catch (SecurityException) { return(null); } catch (IOException) { return(null); } catch (UnauthorizedAccessException) { return(null); } finally { if (registryKey != null) { registryKey.Close(); } } ICredentials credentials; if (createAppTokenOnly) { credentials = OAuthCredentials.GetOAuthCredentialsForAppToken(actAsUserOrgId, "PlaceHolder"); } else { ADObjectId id = actAsUser.Id; ADSessionSettings sessionSettings = ADSessionSettings.FromAllTenantsOrRootOrgAutoDetect(id); IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 552, "GetCredentialAndConfigureClientContext", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\TeamMailbox\\TeamMailboxHelper.cs"); ADUser aduser = tenantOrRootOrgRecipientSession.FindADUserByObjectId(id); credentials = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(actAsUserOrgId, aduser, null); } if (context != null) { context.Credentials = credentials; context.FormDigestHandlingEnabled = false; context.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs args) { args.WebRequestExecutor.RequestHeaders.Add(HttpRequestHeader.Authorization, "Bearer"); args.WebRequestExecutor.RequestHeaders.Add("client-request-id", Guid.NewGuid().ToString()); args.WebRequestExecutor.RequestHeaders.Add("return-client-request-id", "true"); args.WebRequestExecutor.WebRequest.PreAuthenticate = true; args.WebRequestExecutor.WebRequest.UserAgent = Utils.GetUserAgentStringForSiteMailboxRequests(); }; if (num == 1) { context.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs args) { args.WebRequestExecutor.WebRequest.Proxy = new WebProxy("127.0.0.1", 8888); }; } } return(credentials); }
// Token: 0x06001BA6 RID: 7078 RVA: 0x0006A068 File Offset: 0x00068268 private ICredentials GetCredentials() { ADUser accessingADUser = this.callContext.AccessingADUser; return(OAuthCredentials.GetOAuthCredentialsForAppActAsToken(accessingADUser.OrganizationId, accessingADUser, null)); }
// Token: 0x060014EC RID: 5356 RVA: 0x00077EBE File Offset: 0x000760BE public static ICredentials GetOAuthCredentials(ADUser user) { return(OAuthCredentials.GetOAuthCredentialsForAppActAsToken(user.OrganizationId, user, null)); }
// 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); }
public ExchangeProxy(ADUser user, Uri uri, long serverVersion) { OAuthCredentials credentials = new OAuthCredentials(OAuthCredentials.GetOAuthCredentialsForAppActAsToken(user.OrganizationId, user, null)); this.InitializeExchangeProxy(credentials, uri, serverVersion); }