UserName Overwrite with Azure AD – SSO for Identity server

As you probably know, Sitecore is shipping from version 9.1 with the Identity server….

If you want to integrate Sitecore with Azure Active Directory, this resource will walk you through the configuration step by step:

https://sitecore.derekc.net/setting-up-azure-active-directory-integration-with-sitecore-identity-server-sitecore-9-1/

However once you have followed all the steps, you will have an unpleasant surprise when you discover that the Sitecore UserName is mapped with some random unfriendly characters…

randomusername

userlist

As you can probably agree, this is not very user-friendly since the user-name is used in the item version history and within the workflows…

versionhistory

this code snippet will help you to use as user-name, either for the email address as username or the cleaned name of the active directory user…

usermapped

sitecoreauthor