0

Sitecore 10

In the Content Tree when I click on an item being edited by another user, in the review tab, I see in the workflow section, "lkjsadf4f" has locked this item. This is because we are using Okta for Login and the Security Server in Sitecore is assigning a system generated username. So our client can't tell who actually has an item checked out for edit. How can I modify Sitecore to display Full User Name in place of the username which was system generated?

1 Answer 1

3

The generation of the username when using identity server is controlled by the DefaultExternalUserBuilder class. There are some details about this in the documentaiton, but you can override this to generate more meaningful usernames.

Create a class that inherits from DefaultExternalUserBuilder and override the CreateUniqueUserName() method:

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Sitecore.Owin.Authentication.Identity;
using Sitecore.Owin.Authentication.Services;
using Sitecore.SecurityModel.Cryptography;

namespace MyProject.IdentityProvider
{
    public class ExternalUserBuilder : DefaultExternalUserBuilder
    {
        public ExternalUserBuilder(ApplicationUserFactory applicationUserFactory, IHashEncryption hashEncryption) : base(applicationUserFactory, hashEncryption)
        {
        }

        protected override string CreateUniqueUserName(UserManager<ApplicationUser> userManager, ExternalLoginInfo externalLoginInfo)
        {
            string hashDerivedName = base.CreateUniqueUserName(userManager, externalLoginInfo);
            string domain = hashDerivedName.Substring(0, hashDerivedName.IndexOf('\\'));
            string providerKeyName = domain + @"\" + externalLoginInfo.Login.ProviderKey;

            // Check name not already assigned. 
            return userManager.FindByName(providerKeyName) == null ? providerKeyName : hashDerivedName;
        }
    }
}

Modify the line that sets the providerKeyName with the correct values based on the values your ptovider returns.

You can then patch this on your CM server with the following config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set">
  <sitecore>
    <federatedAuthentication>

      <identityProvidersPerSites>
        <mapEntry name="all sites">
          <externalUserBuilder set:type="MyProject.IdentityProvider.ExternalUserBuilder, MyProject.IdentityProvider" resolve="true">
            <IsPersistentUser>true</IsPersistentUser>
          </externalUserBuilder>
        </mapEntry>
      </identityProvidersPerSites>

    </federatedAuthentication>
  </sitecore>
</configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.