I have implemented facebook login on my Sitecore site using federated authentication. I am trying to override the externalUserBuilder logic to be able to replace the hashed username in Sitecore with the email id as indicated here: http://blog.nikkipunjabi.com/2018/03/sitecore-federated-authentication-part-3-sitecore-user-and-claims-identity.html

However, it looks like the code isn't getting executed at all. Any breakpoint in this code isn't being hit, and the user name created is still the hash.

enter image description here

namespace Feature.Accounts.Pipelines.IdentityProviders
    public class CustomExternalUserBuilder : DefaultExternalUserBuilder
        public CustomExternalUserBuilder(string isPersistentUser) : base(bool.Parse(isPersistentUser)) { }

        [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Login")]
        protected override string CreateUniqueUserName(UserManager<ApplicationUser> userManager, ExternalLoginInfo externalLoginInfo)
            //TODO: If Email
            Assert.ArgumentNotNull((object)userManager, nameof(userManager));
            Assert.ArgumentNotNull((object)externalLoginInfo, nameof(externalLoginInfo));
            IdentityProvider identityProvider = this.FederatedAuthenticationConfiguration.GetIdentityProvider(externalLoginInfo.ExternalIdentity);
            if (identityProvider == null)
                throw new InvalidOperationException("Unable to retrieve identity provider for given identity");
            string domain = identityProvider.Domain;
            return domain + "\\" + externalLoginInfo.Email;


enter image description here

Can anyone help me with what I am missing here?

  • 1. Can you show all your "mapEntry" nodes? 2. Make sure that you don't try to debug your CustomExternalUserBuilder class when the user under the test already exists in the DB. Jun 13 '18 at 10:00
  • I have the same problem. Jul 31 '19 at 18:26
  • Closing this since it's unresolved/abandoned by OP
    – Mark Cassidy
    Aug 30 '19 at 20:19

The way I managed to do this is as follows:

<externalUserBuilder type="MyProject.Utility.OktaUserBuilder, MyProject" patch:instead="*[@type='Sitecore.Owin.Authentication.Services.DefaultExternalUserBuilder, Sitecore.Owin.Authentication']">
    <param desc="isPersistentUser">false</param>
  • The reason this works is, the user builder is called on every login for virtual users. For persistent ones, the right place to hook in is the property mapper.
    – Mark Cassidy
    Aug 30 '19 at 20:16

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