locked
The authentication endpoint Username was not found on the configured Secure Token Service! RRS feed

  • Question

  • I am using the Microsoft CRM online and trying to create the Contact Entity and it throwing Authenticon endpoint user name not found exception. Could you please help me out how to resolve this? I have seen lot of forums but didn't found the solution.

    Could you please help me out how to resolve this ?

    OrganizationServiceProxyserviceProxy;

    ClientCredentialsdeviceCredentials = null;

    ClientCredentialsclientCredentials = null;

    GuidcontactId = Guid.Empty;

    //Organization URL

    UriOrganizationUri = newUri("Entered Organization endpoint");

    //Discovery URL

    UriHomeRealmUri = newUri("Entered Discovery address");

    //Setting Client Credentials

    clientCredentials = GetCredentials("Entered the User Name", "Entered my Password");

    //Get the Device Id and Password

    deviceCredentials = this.GetDeviceCredentials();

       clientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

    //Using Organization Service Proxy to instantiate the CRM Web Service

    using(serviceProxy = newOrganizationServiceProxy(OrganizationUri, HomeRealmUri, clientCredentials, deviceCredentials))

    {

    // This statement is required to enable early-bound type support.

    serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(newProxyTypesBehavior());

    IOrganizationServiceservice = (IOrganizationService)serviceProxy;

    //Define Entity Object

    Entitycontact = newEntity("contact");

    //Specify the attributes

    contact.Attributes["lastname"] = txtFName.Text;

    //Execute the service

    contactId = service.Create(contact);

    //Confirmation Message

    message = "Contact Created with LastName:- "+ txtFName.Text + " Guid is"+ contactId.ToString();

    ---------------------------------------------------------

    protectedvirtualClientCredentialsGetCredentials(stringusername, stringpassword)

    {

    ClientCredentialscredentials = newClientCredentials();

    credentials.UserName.UserName = username;

    credentials.UserName.Password = password;

    returncredentials;

    }

    protectedvirtualClientCredentialsGetDeviceCredentials()

    {

    returnMicrosoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();

    }

    Tuesday, September 1, 2015 8:46 PM

All replies

  • My suggestion is that your problem is your credentials and your usage of them.

    //Get the Device Id and Password
     
    deviceCredentials = this.GetDeviceCredentials();
     
       clientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
     
    //Using Organization Service Proxy to instantiate the CRM Web Service
     
    using(serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, clientCredentials, deviceCredentials))

    your clientCredentials should be your CRM Online UserName and Password (with no domain defined). But you appear to be using whatever credentials are of the person logged in, which are you certain is actually a CRM Online person, because I am doubting that.

    Tuesday, September 1, 2015 9:28 PM
  • Here is my code (note that I put these things in the config file) so I can swap between online and onprem systems or my dev system.

    Also note that my homeRealmUri is NULL

                    #region Get our Login Information
    
                    // setup the variables
                    OrganizationServiceProxy _serviceProxy;
    
                    // homeRealmUri will stay null for now
                    Uri homeRealmUri = null;
    
                    // setup credentials from whatever is in the app.config
                    ClientCredentials credentials;
    
                    // same for organizationuri comes from app.config
                    Uri organizationUri;
                    IOrganizationService workFlowService;
    
                    //create the uri
                    string orgUrl = GetProfileUri();
    
                    // set the organization uri from what was in the app.config
                    organizationUri = new Uri(orgUrl);
    
                    //create the credentials
                    string login = GetProfileLogin();
    
                    string pwd = GetProfilePassword();
    
                    string domain = GetProfileDomain();
    
                    if (IsOnline())
                    {
    
                        credentials = new ClientCredentials();
                        credentials.UserName.UserName = login;
                        credentials.UserName.Password = pwd;
                    }
                    else
                    {
                        credentials = new ClientCredentials();
                        credentials.Windows.ClientCredential = new NetworkCredential(login, pwd, domain);
                    }
    
                    #endregion

    and here are my helper functions

           #region Login Helper Functions
            private bool IsOnline()
            {
                string activeProfile = GetActiveProfile();
    
                if (!string.IsNullOrEmpty(activeProfile))
                {
                    if (activeProfile.Contains("online"))
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    throw new ArgumentNullException("Active profile null");
                }
            }
            private string GetActiveProfile()
            {
                try
                {
                    string activeProfile = ConfigurationManager.AppSettings["activeprofile"];
    
                    if (string.IsNullOrEmpty(activeProfile))
                    {
                        throw new ArgumentNullException("Activate Profile Cannot be Null");
                    }
    
                    return activeProfile;
    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error retrieving profile user " + ex.ToString());
                    return string.Empty;
                }
            }
    
            private string GetProfileLogin()
            {
                try
                {
                    string activeProfile = ConfigurationManager.AppSettings["activeprofile"];
    
                    if (string.IsNullOrEmpty(activeProfile))
                    {
                        throw new ArgumentNullException("Activate Profile Cannot be Null");
                    }
    
                    string profileUser = "crm:" + activeProfile + ":login";
    
                    return ConfigurationManager.AppSettings[profileUser];
    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error retrieving profile user " + ex.ToString());
                    return string.Empty;
                }
            }
    
            private string GetProfileDomain()
            {
                try
                {
                    string activeProfile = ConfigurationManager.AppSettings["activeprofile"];
    
                    if (string.IsNullOrEmpty(activeProfile))
                    {
                        throw new ArgumentNullException("Activate Profile Cannot be Null");
                    }
    
                    string profileDomain = "crm:" + activeProfile + ":domain";
    
                    return ConfigurationManager.AppSettings[profileDomain];
    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error retrieving profile domain " + ex.ToString());
                    return string.Empty;
                }
            }
    
            private string GetProfilePassword()
            {
                try
                {
                    string activeProfile = ConfigurationManager.AppSettings["activeprofile"];
    
                    if (string.IsNullOrEmpty(activeProfile))
                    {
                        throw new ArgumentNullException("Activate Profile Cannot be Null");
                    }
    
                    string profilePassword = "crm:" + activeProfile + ":password";
    
                    return ConfigurationManager.AppSettings[profilePassword];
    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error retrieving profile password " + ex.ToString());
                    return string.Empty;
                }
    
            }
    
            private string GetProfileUri()
            {
                try
                {
                    string activeProfile = ConfigurationManager.AppSettings["activeprofile"];
    
                    if (string.IsNullOrEmpty(activeProfile))
                    {
                        throw new ArgumentNullException("Activate Profile Cannot be Null");
                    }
    
                    string profileUri = "crm:" + activeProfile + ":organizationuri";
    
                    return ConfigurationManager.AppSettings[profileUri];
    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error retrieving profile password " + ex.ToString());
                    return string.Empty;
                }
            }
    
            #endregion
    

    Tuesday, September 1, 2015 9:35 PM
  • Wednesday, September 2, 2015 3:53 AM
  • It looks like the supplied code is trying to connect directly to the OrganizationService, without going via the DiscoveryService. One thing the DiscoveryService gives you is the AuthenticationType to use. If you're not specifying the AuthenticationType, then it will default to ActiveDirectory, which is incorrect for Crm Online

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Wednesday, September 2, 2015 7:59 PM
    Moderator