locked
Issues authenticating CRM user using logged in user credentials RRS feed

  • Question

  • I am trying to develop a C# WPF application that will update records in CRM. I want the application to automatically authenticate based on the currently logged in users domain credentials.

    I have read a few tutorials that provide the following code:

    Uri prodOrgUri = new Uri("https://crm.domain.com:<port>/<org>/XRMServices/2011/Organization.svc");
    Uri homeRealmUri = null;
     
    ClientCredentials credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
     
    using (OrganizationServiceProxy _Service = new OrganizationServiceProxy(prodOrgUri, homeRealmUri, credentials, null))
    {
        _Service.EnableProxyTypes();
        IOrganizationService _iOrganizationService =  (IOrganizationService)_Service;
        var context = new XrmServiceContext(_iOrganizationService);
     
        // CRM code
    }
    

    However this always fails to authenticate. I have no problem connecting via this method when I manually define the login credentials, it is only when trying to automatically authenticate the user.

    Debugging the code shows that the ClientCredential object has blank values for domain, username and password.

    Any help in this matter would be much appreciated. Not having the user typing in their login credentials is an integral part of this application.

    Thanks in advance,

    Daniel Di Giandomenico


    Wednesday, October 15, 2014 4:42 AM

All replies

  • Hello,

    Please try to put your code under try/catch block like below

    try{}

    catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)

    {
    }

    and check for ex.Detail.Message


    Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, October 15, 2014 10:53 AM
    Moderator
  • I'm uncomfortable with:

    credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

    please remove that and recompile.

    Also, you should always wrap your code in a try block and catch the organization service fault:

    catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
                    {
                        //Console.WriteLine("The application terminated with an error.");
                        //Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
                        //Console.WriteLine("Code: {0}", ex.Detail.ErrorCode);
                        Console.WriteLine("Message: {0}", ex.Detail.Message);
                        //Console.ReadLine();
                        //Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
                    }

     

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful. Michael Mayo


    Wednesday, October 15, 2014 8:22 PM