+ Start a Discussion
Søren Nødskov HansenSøren Nødskov Hansen 

Create and Log In with External Identity

Hi fellow developers

I'm currently building an integration between an external website (Sitecore) and Salesforce using Identity Management (External Identity User).

I've created a REST Service in Apex which the Sitecore developer calls. The Apex REST Service creates an Account, Contact and User based on the details sent by the Sitecore backend. The Apex REST Service also calls setPassword for the User once it's been created.

We're seeing issues where often we cannot log in using the SOAP API (Partner WSDL) with the User Credentials just created by the Apex REST Service. It almost seems like the setPassword is ignored or simply doesn't take effect (sometimes it works sometimes it doesn't).

I've tried moving the setPassword call into an asynchronous call using the Future keyword. That seemed to work for a while but now when the Sitecore backend calls login with the External Identity's Credentials we run in to a race condition where the Future-method hasn't returned yet when trying to log in.

We then tried moving the setPassword out of the Apex REST Service and instead having Sitecore call setPassword once the External Identity User had been created. Again, there seems to be a timing issue with this approach and it only works on and off.

Finally, we added a wait-command to the Sitecore code so that we're now waiting X seconds between "create user", "set password" and "log in". However, this is of course unacceptable - we cannot have waiting or sleeping threads in our code.

Has anyone else had these issues and is there a way around it? What's the solution - there has to be one... I hope....

Kind regards,
Søren Nødskov Hansen