Last active
January 15, 2020 18:59
-
-
Save steliodibello/79cad52368b68bf5dfb9701005be59d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics.CodeAnalysis; | |
using Microsoft.AspNet.Identity; | |
using Microsoft.AspNet.Identity.Owin; | |
using Sitecore.Diagnostics; | |
using Sitecore.Owin.Authentication.Configuration; | |
using Sitecore.Owin.Authentication.Identity; | |
using Sitecore.Owin.Authentication.Services; | |
using Sitecore.SecurityModel.Cryptography; | |
namespace XXXXX.Foundation.SSO.UserBuilders | |
{ | |
public class XXXExternalUserBuilder : DefaultExternalUserBuilder | |
{ | |
public XXXExternalUserBuilder(ApplicationUserFactory applicationUserFactory, IHashEncryption hashEncryption) : base(applicationUserFactory, hashEncryption) { } | |
protected override string CreateUniqueUserName(UserManager<ApplicationUser> userManager, ExternalLoginInfo externalLoginInfo) | |
{ | |
Sitecore.Diagnostics.Log.Debug("CreateUnique UserName",this); | |
if (externalLoginInfo != null) | |
{ | |
if (!string.IsNullOrWhiteSpace(externalLoginInfo.Email)) | |
{ | |
return externalLoginInfo.Email; | |
} | |
else | |
{ | |
Sitecore.Diagnostics.Log.Debug("empty Email", this); | |
Sitecore.Diagnostics.Log.Debug("default username " + externalLoginInfo.DefaultUserName, this); | |
var validUserName = externalLoginInfo.DefaultUserName.Replace(",", ""); | |
return "sitecore\\" + validUserName.Replace(" ", ""); | |
} | |
} | |
Sitecore.Diagnostics.Log.Error("null UserInfo when creating UserName", this); | |
return "nullUserInfo"; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:localenv="http://www.sitecore.net/xmlconfig/localenv"> | |
<sitecore localenv:require="uat or prd" role:require="Standalone or ContentDelivery or ContentManagement"> | |
<federatedAuthentication> | |
<identityProvidersPerSites hint="list:AddIdentityProvidersPerSites"> | |
<!-- Defines a list of providers assigned to all sites. --> | |
<mapEntry name="all sites" type="Sitecore.Owin.Authentication.Collections.IdentityProvidersPerSitesMapEntry, Sitecore.Owin.Authentication" resolve="true"> | |
<!-- | |
The list of site names for which the specified identity providers will work. | |
Note: the fedauth.siteNameExpander pipeline processes each site name, which gives the ability to use expressions like | |
"regexp:modules_.*" or "database:web" or "domain:extranet" | |
--> | |
<sites hint="list"> | |
<site>regexp:.*</site> | |
</sites> | |
<externalUserBuilder type="XXXX.Foundation.SSO.UserBuilders.XXXXExternalUserBuilder, XXXX.Foundation.SSO" resolve="true"> | |
<IsPersistentUser>true</IsPersistentUser> | |
</externalUserBuilder> | |
</mapEntry> | |
</identityProvidersPerSites> | |
<propertyInitializer> | |
<maps> | |
<map name="set IsAdministrator" type="Sitecore.Owin.Authentication.Services.DefaultClaimToPropertyMapper, Sitecore.Owin.Authentication" resolve="true"> | |
<data hint="raw:AddData"> | |
<source name="http://www.sitecore.net/identity/claims/isAdmin" value="true" /> | |
<target name="IsAdministrator" value="true" /> | |
</data> | |
</map> | |
<map name="set Email" type="Sitecore.Owin.Authentication.Services.DefaultClaimToPropertyMapper, Sitecore.Owin.Authentication" resolve="true"> | |
<data hint="raw:AddData"> | |
<source name="email"/> | |
<target name="Email"/> | |
</data> | |
</map> | |
<map name="set FullName" type="Sitecore.Owin.Authentication.Services.DefaultClaimToPropertyMapper, Sitecore.Owin.Authentication" resolve="true"> | |
<data hint="raw:AddData"> | |
<source name="name"/> | |
<target name="FullName"/> | |
</data> | |
</map> | |
</maps> | |
</propertyInitializer> | |
</federatedAuthentication> | |
</sitecore> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment