none
CRM 2011: Device Credentials Authentication Failure

    Question

  • I have written a simple ASP.NET web page to create a new record in CRM Online (2011) using the OrganizationService web service.

     

    ClientCredentials credentials = new ClientCredentials();
    
    credentials.UserName.UserName = "<WLID>";
    credentials.UserName.Password = "<PASSWORD>";
    
    ClientCredentials deviceCredentials = new ClientCredentials();
    deviceCredentials.UserName.UserName = "<randomchars>";
    deviceCredentials.UserName.Password = "<randomchars>";
    
    Uri organizationUri = new Uri("https://<myorg>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc");
    Uri homeRealmUri = null;
    OrganizationServiceProxy orgService = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials);
    
    Entity account = new Entity("account");
    account["name"] = "SDK";
    
    // Create an account record named SDK
    orgService.Create(account);
    

     

    The code compiles fine but when calling the Create method I get an exception:

    {"Authentication Failure"}

    An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

    I assume this is something to do with the DeviceCredentials but I'm really confused as to how to set this. (I just used 15 random characters)

    What values should I be using? What are they for?


    ePartners CRM
    Wednesday, March 02, 2011 8:15 PM

Answers

  • Ok I finally managed to resolve this doing the following:

    - Delete LiveDevice.xml file from LiveDeviceId folder

    - Reboot

    - Run the DeviceRegistration tool from the SDK

     

    I assume something was cached as when I rebooted the problem finally went away.

    I rarely reboot my machine hence the random errors.


    ePartners CRM
    • Marked as answer by ePartners UK Friday, March 04, 2011 2:50 PM
    Friday, March 04, 2011 2:49 PM

All replies

  • No don't use random characters.

    In the SDK folder, tools folder, there is a device registration tool, execute this command from cmd and it will give you the device credentials which you can copy

    deviceregistration.exe /operation:Register

    If you are using the CRM online then you must use the device credentials too to generate the entities using crmsvcutil.

    Have a look on this article

    http://deepakexploring.wordpress.com/2011/02/16/crud-operation-early-bound-classes-using-wcf-services-in-crm-2011/


    Islam Eldemery
    http://idemery.net
    idemery
    • Proposed as answer by Islam Eldemery Wednesday, March 02, 2011 9:14 PM
    Wednesday, March 02, 2011 9:09 PM
  • I couldn't find an executable so I built the project in VS2010

    When running the exe from "obj\debug" folder, with /operation:Register I get the following error:

    Unhandled Exception: System.InvalidOperationException: There is an error in XML

    document (5, 5). ---> System.Security.Cryptography.CryptographicException: The p

    arameter is incorrect.

     


     


    ePartners CRM
    Wednesday, March 02, 2011 10:53 PM
  • Yes right you got to build it first, try to build it as release and use bin\release folder
    Islam Eldemery
    http://idemery.net
    idemery
    • Proposed as answer by Jim Glass Jr Thursday, March 03, 2011 12:36 AM
    • Unproposed as answer by ePartners UK Thursday, March 03, 2011 11:02 AM
    Thursday, March 03, 2011 12:10 AM
  • As suspected, when I build to release I still get the same error. More details:

    Unhandled Exception: System.InvalidOperationException: There is an error in XML

    document (5, 5). ---> System.Security.Cryptography.CryptographicException: The p

    arameter is incorrect.

       at System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData,

     Byte[] optionalEntropy, DataProtectionScope scope)

       at Microsoft.Crm.Services.Utility.DeviceUserName.Decrypt(String value) in C:\

    Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\DeviceIdManager.cs:li

    ne 876

       at Microsoft.Crm.Services.Utility.DeviceUserName.UpdateCredentials(String enc

    ryptedValue, String decryptedValue) in C:\Users\My Name\Downloads\sdk\Samp

    leCode\CS\HelperCode\DeviceIdManager.cs:line 847

       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLiveDe

    vice.Read2_DeviceUserName(Boolean isNullable, Boolean checkType)

       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLiveDe

    vice.Read3_LiveDevice(Boolean isNullable, Boolean checkType)

       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLiveDe

    vice.Read4_Data()

       --- End of inner exception stack trace ---

       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, St

    ring encodingStyle, XmlDeserializationEvents events)

       at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)

       at Microsoft.Crm.Services.Utility.DeviceIdManager.Deserialize[T](Stream strea

    m) in C:\Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\DeviceIdMana

    ger.cs:line 272

       at Microsoft.Crm.Services.Utility.DeviceIdManager.ReadExistingDevice(String e

    nvironment) in C:\Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\Dev

    iceIdManager.cs:line 323

       at Microsoft.Crm.Services.Utility.DeviceIdManager.LoadDeviceCredentials(Uri i

    ssuerUri) in C:\Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\Devic

    eIdManager.cs:line 218

       at Microsoft.Crm.Services.Utility.LiveDeviceIdUtil.Main(String[] args) in C:\

    Users\My Name\Downloads\sdk\tools\deviceregistration\Program.cs:line 18

     

    Do I need to make any changes before compiling? All I did was open the project and CTRL-SHIFT-B etc


    ePartners CRM
    Thursday, March 03, 2011 11:05 AM
  • What is the size of the downloaded sdk zip file you have?
    Islam Eldemery
    http://idemery.net
    idemery
    Thursday, March 03, 2011 4:39 PM
  • What is the size of the downloaded sdk zip file you have?
    Islam Eldemery
    http://idemery.net
    idemery

    I just downloaded the latest SDK (95,697) and recompiled.

    I get the following error:

    {"The parameter is incorrect.\r\n"}

    I am compiling with VS2010 on a Windows 7 machine.

    C:\Users\My Name\Downloads\sdk\tools\deviceregistration\bin\Debug>DeviceRe
    gistration.exe /operation:Register
    
    Unhandled Exception: System.InvalidOperationException: There is an error in XML
    document (5, 5). ---> System.Security.Cryptography.CryptographicException: The p
    arameter is incorrect.
    
      at System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData,
     Byte[] optionalEntropy, DataProtectionScope scope)
      at Microsoft.Crm.Services.Utility.DeviceUserName.Decrypt(String value) in C:\
    Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\DeviceIdManager.cs:li
    ne 876
      at Microsoft.Crm.Services.Utility.DeviceUserName.UpdateCredentials(String enc
    ryptedValue, String decryptedValue) in C:\Users\My Name\Downloads\sdk\Samp
    leCode\CS\HelperCode\DeviceIdManager.cs:line 849
      at Microsoft.Crm.Services.Utility.DeviceUserName.set_EncryptedPassword(String
     value) in C:\Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\DeviceI
    dManager.cs:line 770
      at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLiveDe
    vice.Read2_DeviceUserName(Boolean isNullable, Boolean checkType)
      at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLiveDe
    vice.Read3_LiveDevice(Boolean isNullable, Boolean checkType)
      at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLiveDe
    vice.Read4_Data()
      --- End of inner exception stack trace ---
      at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, St
    ring encodingStyle, XmlDeserializationEvents events)
      at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
      at Microsoft.Crm.Services.Utility.DeviceIdManager.Deserialize[T](Stream strea
    m) in C:\Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\DeviceIdMana
    ger.cs:line 272
      at Microsoft.Crm.Services.Utility.DeviceIdManager.ReadExistingDevice(String e
    nvironment) in C:\Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\Dev
    iceIdManager.cs:line 325
      at Microsoft.Crm.Services.Utility.DeviceIdManager.LoadDeviceCredentials(Uri i
    ssuerUri) in C:\Users\My Name\Downloads\sdk\SampleCode\CS\HelperCode\Devic
    eIdManager.cs:line 218
      at Microsoft.Crm.Services.Utility.LiveDeviceIdUtil.Main(String[] args) in C:\
    Users\My Name\Downloads\sdk\tools\deviceregistration\Program.cs:line 21
    
    C:\Users\My Name\Downloads\sdk\tools\deviceregistration\bin\Debug>
    
    


    ePartners CRM
    Thursday, March 03, 2011 6:41 PM
  • Try the following, open your user folder (C:\Users\your name\LiveDeviceID\) and delete the LiveDevice.xml and retry again.
    Islam Eldemery
    http://idemery.net
    idemery
    Thursday, March 03, 2011 7:43 PM
  • Hi Islam,

    I already tried deleting the file and running again.

    Unfortunately, whatever command I try the DeviceRegistration returns the same error.


    ePartners CRM
    Thursday, March 03, 2011 8:47 PM
  • When developing my tools (see my signature), I just used the helpers from the SDK and I can tell you that even when using these class written by Microsoft, I get Authentication Failure error message.

    I guess we can't do anything about it... it seems totaly random...


    My blog : http://mscrmtools.blogspot.com

    All my tools for Dynamics CRM 4.0 on my dedicated site: MSCRMTools Repository

    Thursday, March 03, 2011 10:18 PM
    Moderator
  • Ok I finally managed to resolve this doing the following:

    - Delete LiveDevice.xml file from LiveDeviceId folder

    - Reboot

    - Run the DeviceRegistration tool from the SDK

     

    I assume something was cached as when I rebooted the problem finally went away.

    I rarely reboot my machine hence the random errors.


    ePartners CRM
    • Marked as answer by ePartners UK Friday, March 04, 2011 2:50 PM
    Friday, March 04, 2011 2:49 PM
  • Hi  Islam Eldemery,

     

        In MSCRM 2011, when ever you create a lead or account you need Device Credentials. If at all you want to host the same code in Server then, How can we create

        Device Credentials for the server. Can we generate a unique Device Credentials for the Organization?


    Thanks,

    S.B.Raju

     


    S.B.Raju
    Monday, July 25, 2011 1:12 PM