Microsoft KB Archive/862677

From BetaArchive Wiki
Knowledge Base


You receive an "Invalid user auth" error message when you manually load the credential cache and manipulate the CUserAuth structure

PSS ID Number: 862677

Article Last Modified on 5/6/2005



The information in this article applies to:

  • Microsoft Business Solutions CRM Software Development Kit (SDK), when used with:
    • Microsoft Business Solutions CRM 1.2
    • Microsoft Business Solutions CRM 1.0



TechKnowledge Content

SYMPTOMS

An application that makes several platform calls to Microsoft CRM has been created in which the CRM Object credentials are manually set to a specific user. It makes calls as two different users. When the CUserAuth is changed to a user other than the user that was manually loaded in the credential cache, you may receive the following error message:

<detail><error>80040204<description>Invalid user auth.</description>
<details>The user ID does not match the thread token.</details><file>;d:\mscrm\build\3017\src\platform\security\crmsecurity\secmain.cpp</file><line>527</line></error></detail>



The following scenario explains the business requirement you are trying to resolve:

When a Phone Activity is updated, a custom field on the associated Account (specified in the regarding field of the phone activity) should be set with the date and time. The Account update needs to be done by the same user that updated the Phone Activity for auditing and reporting purposes. To accomplish this, the following plan was designed.

1. Use Post-Callouts to respond to the phone activity update and send the activityid and xml to Microsoft Message Queueing (MSMQ).
2. Create a windows service to retrieve the message from MSMQ.
a. From the original xml, extract the activitytypecode to determine if the activity is a phone activity.
b. From the original xml, extract the modifiedby value to get the user that updated the phone activity.
c. Use the BizUser.Retrieve method to get the businessunitid for the modifiedby user. In order to do this, the bizUser credentials are forced to a user who has rights to retrieve user information using the code below. The reason they are forced is because the user that performed the phone activity update may not have the rights to retrieve the BizUser information.

     CredentialCache credentialCache = new CredentialCache();

   NetworkCredential credentials = new NetworkCredential("CRMUser","CRMPassword","CRMDomain");

   credentialCache.Add(new Uri("http://SERVER"), "NTLM", credentials);

   bizUser.Credentials = credentialCache; 



d. Set the CUserAuth.UserId and CUserAuth.MerchantId to these values so that the account is updated by the same user that performed the phone activity update.
e. Update the custom field on the account using the CRMAccount.Update.

CAUSE

The error is returned because the user credentials that are being forced in step 2c do not match the userAuth that is being set in step 2d.

RESOLUTION

The CRMUser account must be added as a member of the PrivUserGroup in Active Directory. The platform will not force the token and CUserAuth to match; instead, it will use CUserAuth to set the details for the CRMAccount.Update call.

To add the CRMUser to the PrivUserGroup, perform the following steps:

1. Launch Active Directory Users and Computers. Click Start, point to Programs, click Administrative Tools, and then click Active Directory Users and Computers.

2. Expand the tree and click your Microsoft CRM Organizational Unit (Adventure Works Cycle).

3. In the right panel, right-click PrivUserGroup and select Properties to open the PrivUserGroup Properties window.

4. Click the Members tab.

5. Click the Add button to open the Select Users, Contacts, Computers or Groups window.

6. Locate the CRMUser that was used in your code (step 2c above) and then click Add.

7. Click OK to close the Select Users, Contacts, Computers or Groups window.

8. Click OK to close the PrivUserGroup Properties window.

9. Close Active Directory Users and Groups.

REFERENCES

1. For more information about Post-Callouts, visit the following MSDN Web sites:

CRM Version 1: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmbscrm/html/mbs_crmpostcallouts.asp

CRM Version 1.2: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmbscrm1_2/html/mbs_crmpostcalloutsv1d2.asp

2. For more information about the BizUser.Retrieve Method,, visit the following MSDN Web sites:

CRM Version 1: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk/htm/bizuserretrievemethod.asp

CRM Version 1.2: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk1_2/htm/v1d2bizuserretrievemethod.asp

3. For more information about the CRMAccount.Update Method, visit the following MSDN Web sites:

CRM Version 1: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk/htm/crmaccountupdatemethod.asp

CRM Version 1.2: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk1_2/htm/v1d2crmaccountupdatemethod.asp

This article was TechKnowledge Document ID: 35005

Keywords: kbMBSMigrate KB862677
Technology: kbBizSolSearch kbCRM kbCRMSDK kbCRMSearch