private List <ProfileColumn> SetDefaultColumns(Int32 IdProfileType, AuthenticationProviderType authentication) { List <ProfileColumn> columns = new List <ProfileColumn>(); columns.Add(ProfileColumn.name); columns.Add(ProfileColumn.statusIcon); columns.Add(ProfileColumn.status); columns.Add(ProfileColumn.authentication); if (IdProfileType == (int)UserTypeStandard.Company) { columns.Add(ProfileColumn.companyName); } if (IdProfileType == (int)UserTypeStandard.Employee) { columns.Add(ProfileColumn.agency); } if (authentication == AuthenticationProviderType.Internal) { columns.Add(ProfileColumn.login); } View.AvailableColumns = columns; return(columns); }
private void MoveFromStepUnknownProfileDisclaimer() { AuthenticationProviderType sProvider = View.SelectedProvider; UpdateStepsToSkipForInternal(sProvider); if (sProvider == AuthenticationProviderType.Internal) { View.GotoStep(ProfileWizardStep.InternalCredentials); } else { if (View.TokenIdOrganization > 0 && View.TokenIdProfileType > 0) { MoveToNextStep(ProfileWizardStep.ProfileTypeSelector); } else if (View.TokenIdOrganization > 0) { MoveToNextStep(ProfileWizardStep.OrganizationSelector); } else if (View.AvailableOrganizationsId.Count <= 1 && View.SelectedOrganizationId > 0) { UpdateStepsToSkip(ProfileWizardStep.OrganizationSelector, true); MoveToNextStep(ProfileWizardStep.OrganizationSelector); } else { View.GotoStep(ProfileWizardStep.OrganizationSelector); UpdateStepsToSkip(ProfileWizardStep.OrganizationSelector, false); } } }
public ClientCredentials GetCredentials(AuthenticationProviderType providerType, string domain, string username, string password) { var creds = new ClientCredentials(); switch (providerType) { case AuthenticationProviderType.Federation: case AuthenticationProviderType.LiveId: if (string.IsNullOrEmpty(domain)) { creds.UserName.UserName = username; creds.UserName.Password = password; } else { creds.UserName.UserName = string.Concat(domain, @"\", username); creds.UserName.Password = password; } break; case AuthenticationProviderType.ActiveDirectory: creds.Windows.ClientCredential = string.IsNullOrEmpty(domain) ? new NetworkCredential(username, password) : new NetworkCredential(username, password, domain); break; default: break; } return creds; }
/// <summary> /// /// </summary> public void Run() { //<snippetAuthenticateWithNoHelp1> IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>( new Uri(_discoveryServiceAddress)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; // Set the credentials. AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType); String organizationUri = String.Empty; // Get the discovery service proxy. using (DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials)) { // Obtain organization information from the Discovery service. if (discoveryProxy != null) { // Obtain information about the organizations that the system user belongs to. OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy); // Obtains the Web address (Uri) of the target organization. organizationUri = FindOrganization(_organizationUniqueName, orgs.ToArray()).Endpoints[EndpointType.OrganizationService]; } } //</snippetAuthenticateWithNoHelp1> if (!String.IsNullOrWhiteSpace(organizationUri)) { //<snippetAuthenticateWithNoHelp3> IServiceManagement <IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>( new Uri(organizationUri)); // Set the credentials. AuthenticationCredentials credentials = GetCredentials(orgServiceManagement, endpointType); // Get the organization service proxy. using (OrganizationServiceProxy organizationProxy = GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials)) { // This statement is required to enable early-bound type support. organizationProxy.EnableProxyTypes(); // Now make an SDK call with the organization service proxy. // Display information about the logged on user. Guid userid = ((WhoAmIResponse)organizationProxy.Execute( new WhoAmIRequest())).UserId; SystemUser systemUser = organizationProxy.Retrieve("systemuser", userid, new ColumnSet(new string[] { "firstname", "lastname" })).ToEntity <SystemUser>(); Console.WriteLine("Logged on user is {0} {1}.", systemUser.FirstName, systemUser.LastName); } //</snippetAuthenticateWithNoHelp3> } }
private AuthenticationCredentials GetCredentials(AuthenticationProviderType endpointType) { AuthenticationCredentials authCredentials = new AuthenticationCredentials(); switch (endpointType) { case AuthenticationProviderType.ActiveDirectory: authCredentials.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(_userName, _password, _domain); break; case AuthenticationProviderType.LiveId: authCredentials.ClientCredentials.UserName.UserName = _userName; authCredentials.ClientCredentials.UserName.Password = _password; authCredentials.SupportingCredentials = new AuthenticationCredentials(); authCredentials.SupportingCredentials.ClientCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice(); break; default: // For Federated and OnlineFederated environments. authCredentials.ClientCredentials.UserName.UserName = _userName; authCredentials.ClientCredentials.UserName.Password = _password; // For OnlineFederated single-sign on, you could just use current UserPrincipalName instead of passing user name and password. // authCredentials.UserPrincipalName = UserPrincipal.Current.UserPrincipalName; //Windows/Kerberos break; } return(authCredentials); }
/// <summary> /// /// </summary> public OrganizationServiceProxy GetOrganizationProxy() { IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(new Uri(DiscoveryServiceAddress)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType); String organizationUri = String.Empty; // Get the discovery service proxy. using (DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials)) { // Obtain organization information from the Discovery service. if (discoveryProxy != null) { // Obtain information about the organizations that the system user belongs to. OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy); // Obtains the Web address (Uri) of the target organization. organizationUri = FindOrganization(OrganizationUniqueName, orgs.ToArray()).Endpoints[EndpointType.OrganizationService]; } } IServiceManagement <IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>(new Uri(organizationUri)); // Set the credentials. AuthenticationCredentials credentials = GetCredentials(orgServiceManagement, endpointType); // Get the organization service proxy. return(GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials)); }
private string GetUrlString(AuthenticationProviderType auth) { var url = ConnectionDetail.OrganizationServiceUrl; url = Settings.UseConnectionString ? url.Replace(@"/XRMServices/2011/Organization.svc", string.Empty) : url; if (auth == AuthenticationProviderType.ActiveDirectory) { return(url); } int start; var prefix = url.SubstringByString(0, "//", out start) + "//"; if (start < 0) { return(url); } var end = url.IndexOf(".", start, StringComparison.Ordinal); if (end < 0) { return(url); } return(prefix + ConnectionDetail.OrganizationUrlName + url.Substring(end)); }
public static OrganizationServiceProxy getProxy() { IServiceManagement <IOrganizationService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>(new Uri(OrganizationUri)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; if (endpointType == AuthenticationProviderType.LiveId) { var connectionString = getConnectionString(); var connection = CrmConnection.Parse(connectionString); OrganizationService servicio = new OrganizationService(connection); IOrganizationService _service = (IOrganizationService)servicio.InnerService; OrganizationServiceProxy _proxy = (OrganizationServiceProxy)_service; return(_proxy); } else if (endpointType == AuthenticationProviderType.ActiveDirectory) { ClientCredentials credentials = new ClientCredentials(); credentials.Windows.ClientCredential = new System.Net.NetworkCredential(UserName, Password, dominio); OrganizationServiceProxy _proxy = new OrganizationServiceProxy(new Uri(OrganizationUri), null, credentials, null); return(_proxy); } else //esta será la que realmente se utilice en el caso del nuevo Crm online { AuthenticationCredentials authCredentials = new AuthenticationCredentials(); authCredentials.ClientCredentials.UserName.UserName = UserName; authCredentials.ClientCredentials.UserName.Password = Password; OrganizationServiceProxy _proxy = GetProxy <IOrganizationService, OrganizationServiceProxy>(serviceManagement, authCredentials); return(_proxy); } }
/// <summary> /// Parse credentials from a xml node to required ClientCredentials data type /// based on passed AuthenticationProviderType. /// </summary> /// <param name="credentials">Credential xml node.</param> /// <param name="endpointType">AuthenticationProviderType of the credential.</param> /// <returns>Required ClientCredentials type.</returns> private ClientCredentials ParseInCredentials(XElement credentials, AuthenticationProviderType endpointType) { ClientCredentials result = new ClientCredentials(); switch (endpointType) { case AuthenticationProviderType.ActiveDirectory: result.Windows.ClientCredential = new System.Net.NetworkCredential() { UserName = credentials.Element("UserName").Value, Domain = credentials.Element("Domain").Value }; break; case AuthenticationProviderType.LiveId: result.UserName.UserName = credentials.Element("UserName").Value; break; case AuthenticationProviderType.Federation: result.UserName.UserName = credentials.Element("UserName").Value; break; default: break; } return(result); }
private void UpdateStepsToSkipForInternal(AuthenticationProviderType provider) { List <ProfileWizardStep> available = View.AvailableSteps; if (provider == AuthenticationProviderType.Internal) { UpdateStepsToSkip(ProfileWizardStep.InternalCredentials, false); if (available.Contains(ProfileWizardStep.OrganizationSelector)) { UpdateStepsToSkip(ProfileWizardStep.OrganizationSelector, true); } if (available.Contains(ProfileWizardStep.ProfileTypeSelector)) { UpdateStepsToSkip(ProfileWizardStep.ProfileTypeSelector, true); } UpdateStepsToSkip(ProfileWizardStep.ProfileUserData, true); UpdateStepsToSkip(ProfileWizardStep.Summary, true); UpdateStepsToSkip(ProfileWizardStep.WaitingLogon, false); } else { UpdateStepsToSkip(ProfileWizardStep.InternalCredentials, true); if (available.Contains(ProfileWizardStep.OrganizationSelector)) { UpdateStepsToSkip(ProfileWizardStep.OrganizationSelector, false); } if (available.Contains(ProfileWizardStep.ProfileTypeSelector)) { UpdateStepsToSkip(ProfileWizardStep.ProfileTypeSelector, false); } UpdateStepsToSkip(ProfileWizardStep.ProfileUserData, false); UpdateStepsToSkip(ProfileWizardStep.Summary, false); UpdateStepsToSkip(ProfileWizardStep.WaitingLogon, true); } }
internal Configuration(string serverAddress, string organizationName, AuthenticationProviderType endpointType) : this() { ServerAddress = serverAddress; OrganizationName = organizationName; EndpointType = endpointType; }
public PersonAuthenticationProvider(AuthenticationProviderType providerType, IUserRepository users, IMobileLoginRepository mobileLogins, ITokenHelper tokenHelper, ISmsService smsService) : base(mobileLogins, smsService) { _users = users; ProviderType = providerType; _tokenHelper = tokenHelper; }
protected virtual async Task<LoginUserResult> PrepareOneTimePassword(AuthenticationProviderType providerType, string cellPhone, string externalUserId) { var oneTimePassword = await _logins.Query() .Where(m => m.Provider == providerType && m.ExternalUserId == externalUserId && m.IsUsed == false) .Select(m => m.Code) .FirstOrDefaultAsync(); int mobileCode; if (oneTimePassword == default) { mobileCode = RandomPassword.RandomNumberGenerator(); try { var sendSms = await _smsService.SendAssist($"SAAT {DateTime.Now.ToShortTimeString()} TALEP ETTIGINIZ 24 SAAT GECERLI PAROLANIZ : {mobileCode}", cellPhone); _logins.Add(new MobileLogin { Code = mobileCode, IsSend = sendSms, SendDate = DateTime.Now, ExternalUserId = externalUserId, Provider = providerType, IsUsed = false }); await _logins.SaveChangesAsync(); } catch { return new LoginUserResult { Message = Messages.SmsServiceNotFound, Status = LoginUserResult.LoginStatus.ServiceError }; } } else { mobileCode = oneTimePassword; } return new LoginUserResult { Message = Messages.SendMobileCode + mobileCode, Status = LoginUserResult.LoginStatus.Ok }; }
private void GetOrganizationCollection(object monitorSync, Uri discoveryUri, out OrganizationDetailCollection orgs) { IServiceManagement <IDiscoveryService> serviceManagement; try { serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(discoveryUri); } catch (Exception) { orgs = null; return; } AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType); using (DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials)) { orgs = DiscoverOrganizations(discoveryProxy); } lock (monitorSync) { Monitor.Pulse(monitorSync); } }
public ClientCredentials GetCredentials(AuthenticationProviderType providerType, string domain, string username, string password) { var creds = new ClientCredentials(); switch (providerType) { case AuthenticationProviderType.Federation: case AuthenticationProviderType.LiveId: if (string.IsNullOrEmpty(domain)) { creds.UserName.UserName = username; creds.UserName.Password = password; } else { creds.UserName.UserName = string.Concat(domain, @"\", username); creds.UserName.Password = password; } break; case AuthenticationProviderType.ActiveDirectory: creds.Windows.ClientCredential = string.IsNullOrEmpty(domain) ? new NetworkCredential(username, password) : new NetworkCredential(username, password, domain); break; default: break; } return(creds); }
/// <summary> /// Parse ClientCredentials in to xml node. /// </summary> /// <param name="clientCredentials">ClientCredentials type.</param> /// <param name="endpointType">AuthenticationProviderType of the credentials.</param> /// <returns>Xml node containing credentials data.</returns> private XElement ParseOutCredentials(ClientCredentials clientCredentials, AuthenticationProviderType endpointType) { if (clientCredentials != null) { switch (endpointType) { case AuthenticationProviderType.ActiveDirectory: return(new XElement("Credentials", new XElement("UserName", clientCredentials.Windows.ClientCredential.UserName), new XElement("Domain", clientCredentials.Windows.ClientCredential.Domain) )); case AuthenticationProviderType.LiveId: return(new XElement("Credentials", new XElement("UserName", clientCredentials.UserName.UserName) )); case AuthenticationProviderType.Federation: return(new XElement("Credentials", new XElement("UserName", clientCredentials.UserName.UserName) )); default: break; } } return(new XElement("Credentials", "")); }
private ListViewGroup GetGroup(AuthenticationProviderType type) { string groupName = string.Empty; switch (type) { case AuthenticationProviderType.ActiveDirectory: groupName = "OnPremise"; break; case AuthenticationProviderType.OnlineFederation: groupName = "CRM Online - Office 365"; break; case AuthenticationProviderType.LiveId: groupName = "CRM Online - CTP"; break; case AuthenticationProviderType.Federation: groupName = "Claims authentication - Internet Facing Deployment"; break; } var group = lvConnections.Groups.Cast <ListViewGroup>().FirstOrDefault(g => g.Name == groupName); if (group == null) { group = new ListViewGroup(groupName, groupName); lvConnections.Groups.Add(group); } return(group); }
/// <summary> /// Obtain the AuthenticationCredentials based on AuthenticationProviderType. /// </summary> /// <param name="endpointType">An AuthenticationProviderType of the CRM environment.</param> /// <returns>Get filled credentials.</returns> private AuthenticationCredentials GetCredentials(AuthenticationProviderType endpointType) { var authCredentials = new AuthenticationCredentials(); switch (endpointType) { case AuthenticationProviderType.ActiveDirectory: authCredentials.ClientCredentials.Windows.ClientCredential = new NetworkCredential(CrmConfig.Username, CrmConfig.Password, CrmConfig.Domain); break; case AuthenticationProviderType.LiveId: authCredentials.ClientCredentials.UserName.UserName = CrmConfig.Username; authCredentials.ClientCredentials.UserName.Password = CrmConfig.Password; authCredentials.SupportingCredentials = new AuthenticationCredentials(); authCredentials.SupportingCredentials.ClientCredentials = DeviceIdManager.LoadOrRegisterDevice(); break; case AuthenticationProviderType.None: authCredentials.ClientCredentials = new ClientCredentials(); authCredentials.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; break; default: // For Federated and OnlineFederated environments. authCredentials.ClientCredentials.UserName.UserName = CrmConfig.Username; authCredentials.ClientCredentials.UserName.Password = CrmConfig.Password; // For OnlineFederated single-sign on, you could just use current UserPrincipalName instead of passing user name and password. // authCredentials.UserPrincipalName = UserPrincipal.Current.UserPrincipalName; //Windows/Kerberos break; } return authCredentials; }
//_userId = new Guid("870BEBB1-8C42-E611-80EA-5065F38BF4F1"); public static IOrganizationService ConnectToMSCRM() { try { var discoveryUri = ConfigurationManager.AppSettings["DiscoveryUri"]; IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>( new Uri(discoveryUri)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; // Set the credentials. AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType); Uri serviceUri = new Uri(ConfigurationSettings.AppSettings["OrganizationUri"]); OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, authCredentials.ClientCredentials, null); proxy.EnableProxyTypes(); IOrganizationService service = (IOrganizationService)proxy; return(service); } catch (Exception ex) { MessageBox.Show("Error while connecting to CRM " + ex.Message, "CRM connection", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
public IOrganizationService GetOrgService(string orgname) { try { var customerCredentials = new CustomerCredentialsHandler().GetCredentials(orgname); var discoveryUri = customerCredentials.discoveryurl; //ConfigurationManager.AppSettings["DiscoveryUri"]; IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>( new Uri(discoveryUri)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; // Set the credentials. AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType, customerCredentials); Uri serviceUri = new Uri(customerCredentials.orgurl); //ConfigurationSettings.AppSettings["OrganizationUri"]); OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, authCredentials.ClientCredentials, null); proxy.EnableProxyTypes(); IOrganizationService service = (IOrganizationService)proxy; return(service); } catch (SoapException ex) { throw new Exception(ex.Message); } catch (Exception ex) { throw new Exception(ex.Message); } }
public OrganizationHelper(Uri uri, AuthenticationProviderType ap, string userName, string password, string domain = null) { _uri = uri; _ap = ap; _userName = userName; _password = password; _domain = domain; }
public IAuthenticationProvider SelectProvider(AuthenticationProviderType type) { return(type switch { AuthenticationProviderType.Person => (IAuthenticationProvider)_serviceProvider.GetService(typeof(PersonAuthenticationProvider)), AuthenticationProviderType.Agent => (IAuthenticationProvider)_serviceProvider.GetService(typeof(AgentAuthenticationProvider)), _ => throw new ApplicationException($"Authentication provider not found: {type}") });
public OrganizationHelper() { _uri = new Uri(GetConnectionString("CrmUri") ?? ""); _ap = (AuthenticationProviderType)Enum.Parse(typeof(AuthenticationProviderType), GetConnectionString("CrmAp")); _userName = GetConnectionString("CrmUsr"); _password = GetConnectionString("CrmPwd"); _domain = GetConnectionString("CrmDmn"); }
protected XrmServiceContext CreateXrmServiceContext(MergeOption?mergeOption = null) { string organizationUri = ConfigurationManager.AppSettings["organizationUri"]; //IServiceManagement<IOrganizationService> OrganizationServiceManagement = null; //AuthenticationProviderType OrgAuthType; //AuthenticationCredentials authCredentials = null; //AuthenticationCredentials tokenCredentials = null; //OrganizationServiceProxy organizationProxy = null; //SecurityTokenResponse responseToken = null; //try //{ // OrganizationServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(organizationUri)); // OrgAuthType = OrganizationServiceManagement.AuthenticationType; // authCredentials = GetCredentials(OrgAuthType); // tokenCredentials = OrganizationServiceManagement.Authenticate(authCredentials); // organizationProxy = null; // responseToken = tokenCredentials.SecurityTokenResponse; //} //catch //{ //} IServiceManagement <IOrganizationService> OrganizationServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>(new Uri(organizationUri)); AuthenticationProviderType OrgAuthType = OrganizationServiceManagement.AuthenticationType; AuthenticationCredentials authCredentials = GetCredentials(OrgAuthType); AuthenticationCredentials tokenCredentials = OrganizationServiceManagement.Authenticate(authCredentials); OrganizationServiceProxy organizationProxy = null; SecurityTokenResponse responseToken = tokenCredentials.SecurityTokenResponse; if (ConfigurationManager.AppSettings["CRM_AuthenticationType"] == "ActiveDirectory") { using (organizationProxy = new OrganizationServiceProxy(OrganizationServiceManagement, authCredentials.ClientCredentials)) { organizationProxy.EnableProxyTypes(); } } else { using (organizationProxy = new OrganizationServiceProxy(OrganizationServiceManagement, responseToken)) { organizationProxy.EnableProxyTypes(); } } IOrganizationService service = (IOrganizationService)organizationProxy; var context = new XrmServiceContext(service); if (context != null && mergeOption != null) { context.MergeOption = mergeOption.Value; } return(context); }
private void MoveToProviderInfo(AuthenticationProviderType type) { switch (type) { case AuthenticationProviderType.Internal: dtoInternalProvider internalProvider = new dtoInternalProvider(); internalProvider.IdentifierFields = IdentifierField.none; internalProvider.ChangePasswordAfterDays = 180; internalProvider.AllowAdminProfileInsert = true; internalProvider.DisplayToUser = true; internalProvider.AllowMultipleInsert = false; View.LoadProviderInfo(internalProvider, false); break; case AuthenticationProviderType.Url: dtoUrlProvider urlProvider = new dtoUrlProvider(); urlProvider.IdentifierFields = IdentifierField.stringField; urlProvider.VerifyRemoteUrl = false; urlProvider.AllowAdminProfileInsert = true; urlProvider.DisplayToUser = false; urlProvider.AllowMultipleInsert = true; urlProvider.TokenFormat = UrlUserTokenFormat.LoginDateTime; urlProvider.EncryptionInfo.EncryptionAlgorithm = Authentication.Helpers.EncryptionAlgorithm.Rijndael; View.LoadProviderInfo(urlProvider, false); break; case AuthenticationProviderType.UrlMacProvider: dtoMacUrlProvider macProvider = new dtoMacUrlProvider(); macProvider.IdentifierFields = IdentifierField.stringField; macProvider.VerifyRemoteUrl = false; macProvider.AllowAdminProfileInsert = true; macProvider.DisplayToUser = false; macProvider.AllowMultipleInsert = true; macProvider.AutoAddAgency = true; macProvider.AutoEnroll = true; macProvider.AllowTaxCodeDuplication = true; macProvider.EncryptionInfo.EncryptionAlgorithm = Authentication.Helpers.EncryptionAlgorithm.Md5; macProvider.AllowRequestFromIpAddresses = ""; macProvider.DenyRequestFromIpAddresses = ""; View.LoadProviderInfo(macProvider, false); break; default: dtoProvider provider = new dtoProvider(); provider.AllowAdminProfileInsert = true; provider.DisplayToUser = true; provider.AllowMultipleInsert = false; provider.IdentifierFields = IdentifierField.stringField; View.LoadProviderInfo(provider, false); break; } View.GotoStep(ProviderWizardStep.ProviderData); }
public Microsoft.Xrm.Sdk.IOrganizationService GetService(string serverURL, string userName, string userPassword, string userDomain, string organizationCRM) { //to ignore certificates errors ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertificatePolicy); IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>( new Uri(string.Format("{0}/XRMServices/2011/Discovery.svc", serverURL))); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; // Set the credentials. AuthenticationCredentials authCredentials = GetCredentials(endpointType, userName, userPassword, userDomain); String organizationUri = String.Empty; // Get the discovery service proxy. DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials); // Obtain organization information from the Discovery service. if (discoveryProxy != null) { // Obtain information about the organizations that the system user belongs to. OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy); // Obtains the Web address (Uri) of the target organization. organizationUri = FindOrganization(organizationCRM, orgs.ToArray()).Endpoints[EndpointType.OrganizationService]; } if (!String.IsNullOrWhiteSpace(organizationUri)) { IServiceManagement <IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>( new Uri(organizationUri)); // Set the credentials. AuthenticationCredentials credentials = GetCredentials(endpointType, userName, userPassword, userDomain); // Get the organization service proxy. OrganizationServiceProxy organizationProxy = GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials); // This statement is required to enable early-bound type support. organizationProxy.EnableProxyTypes(); return(organizationProxy); } return(null); }
internal void CreateCrmConnection(AuthenticationProviderType authType, ConnectionCredentials connectionCredentials) { try { string connectionString = GetConnectionString(authType, connectionCredentials); ServiceClient = new CrmServiceClient(connectionString); } catch (Exception ex) { throw ex; } }
public AuthHelper( string url, string username, string password, AuthenticationProviderType provider = AuthenticationProviderType.OnlineFederation, string domain = null) { this.url = url; this.username = username; this.password = password; this.provider = provider; this.domain = domain; }
public bool CreateCRMConnection(AuthenticationProviderType authType, ConnectionCredentials connectionCredentials, int maxNumberOfConnections) { try { var crmConnection = new Connection(maxNumberOfConnections, maxNumberOfConnections); crmConnection.CreateCrmConnection(authType, connectionCredentials); CrmConnections[connectionCredentials.OrganizationUrl] = crmConnection; return(true); } catch (Exception ex) { throw ex; } }
public IAuthenticationProvider SelectProvider(AuthenticationProviderType type) { switch (type) { case AuthenticationProviderType.Person: return((IAuthenticationProvider)serviceProvider.GetService(typeof(PersonAuthenticationProvider))); case AuthenticationProviderType.Agent: return((IAuthenticationProvider)serviceProvider.GetService(typeof(AgentAuthenticationProvider))); default: throw new ApplicationException($"Authentication provider not found: {type}"); } }
public static IAuthentication GetAuthenticationModule(AuthenticationProviderType type) { switch (type) { case AuthenticationProviderType.ActiveDirectory: return(new ADAuthentication()); case AuthenticationProviderType.LDAP: return(new LDAPAuthentication()); case AuthenticationProviderType.None: default: throw new NotSupportedException("Authentication Provider Type is not supported"); } }
private AuthenticationCredentials GetCredentials(AuthenticationProviderType endpointType) { //Load the credentials from the Web.config first //string userName = ConfigurationManager.AppSettings["CRM_Username"]; //string password = ConfigurationManager.AppSettings["CRM_Password"]; //string domain = ConfigurationManager.AppSettings["CRM_Domain"]; string userName = "******"; string password = "******"; string domain = ""; //Load the auth type string authenticationType = ConfigurationManager.AppSettings["CRM_AuthenticationType"]; AuthenticationCredentials authCreds = new AuthenticationCredentials(); switch (authenticationType) { case "ActiveDirectory": authCreds.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain); break; case "LiveId": authCreds.ClientCredentials.UserName.UserName = userName; authCreds.ClientCredentials.UserName.Password = password; authCreds.SupportingCredentials = new AuthenticationCredentials(); authCreds.SupportingCredentials.ClientCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice(); break; case "Online": // For Federated and OnlineFederated environments. authCreds.ClientCredentials.UserName.UserName = userName; authCreds.ClientCredentials.UserName.Password = password; break; case "SSO": //Single Sign On // For OnlineFederated single-sign on, you could just use current UserPrincipalName instead of passing user name and password. authCreds.UserPrincipalName = UserPrincipal.Current.UserPrincipalName; //Windows/Kerberos break; default: // Online authCreds.ClientCredentials.UserName.UserName = userName; authCreds.ClientCredentials.UserName.Password = password; break; } return authCreds; }
/// <summary> /// Parse ClientCredentials into XML node. /// </summary> /// <param name="clientCredentials">ClientCredentials type.</param> /// <param name="endpointType">AuthenticationProviderType of the credentials.</param> /// <returns>XML node containing credentials data.</returns> private XElement ParseOutCredentials(ClientCredentials clientCredentials, AuthenticationProviderType endpointType) { if (clientCredentials != null) { switch (endpointType) { case AuthenticationProviderType.ActiveDirectory: return new XElement("Credentials", new XElement("UserName", clientCredentials.Windows.ClientCredential.UserName), new XElement("Domain", clientCredentials.Windows.ClientCredential.Domain), new XElement("Password", clientCredentials.Windows.ClientCredential.Password) ); case AuthenticationProviderType.LiveId: case AuthenticationProviderType.Federation: case AuthenticationProviderType.OnlineFederation: return new XElement("Credentials", new XElement("UserName", clientCredentials.UserName.UserName) ); default: break; } } return new XElement("Credentials", ""); }
private string GetUrlString(AuthenticationProviderType auth) { var url = ConnectionDetail.OrganizationServiceUrl; url = Settings.UseConnectionString ? url.Replace(@"/XRMServices/2011/Organization.svc", string.Empty) : url; if (auth == AuthenticationProviderType.ActiveDirectory) { return url; } int start; var prefix = url.SubstringByString(0, "//", out start) + "//"; if (start < 0) { return url; } var end = url.IndexOf(".", start, StringComparison.Ordinal); if (end < 0) { return url; } return prefix + ConnectionDetail.OrganizationUrlName + url.Substring(end); }
private ListViewGroup GetGroup(AuthenticationProviderType type) { string groupName = string.Empty; switch (type) { case AuthenticationProviderType.ActiveDirectory: groupName = "OnPremise"; break; case AuthenticationProviderType.OnlineFederation: groupName = "CRM Online - Office 365"; break; case AuthenticationProviderType.LiveId: groupName = "CRM Online - CTP"; break; case AuthenticationProviderType.Federation: groupName = "Claims authentication - Internet Facing Deployment"; break; } var group = lvConnections.Groups.Cast<ListViewGroup>().FirstOrDefault(g => g.Name == groupName); if (group == null) { group = new ListViewGroup(groupName, groupName); lvConnections.Groups.Add(group); } return group; }
private ClientCredentials ParseInCredentials(XElement credentials, AuthenticationProviderType endpointType) { ClientCredentials result = new ClientCredentials(); switch (endpointType) { case AuthenticationProviderType.ActiveDirectory: result.Windows.ClientCredential = new System.Net.NetworkCredential() { UserName = credentials.Element("UserName").Value, Domain = credentials.Element("Domain").Value }; break; case AuthenticationProviderType.LiveId: case AuthenticationProviderType.Federation: case AuthenticationProviderType.OnlineFederation: result.UserName.UserName = credentials.Element("UserName").Value; break; default: break; } return result; }