diff --git a/src/VirtoCommerce.Xapi.Data/Services/ExternalSignInUserBuilder.cs b/src/VirtoCommerce.Xapi.Data/Services/ExternalSignInUserBuilder.cs index 6f957a1..2c26588 100644 --- a/src/VirtoCommerce.Xapi.Data/Services/ExternalSignInUserBuilder.cs +++ b/src/VirtoCommerce.Xapi.Data/Services/ExternalSignInUserBuilder.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; @@ -14,15 +15,16 @@ namespace VirtoCommerce.Xapi.Data.Services; public class ExternalSignInUserBuilder(IStoreService storeService, IMemberService memberService) : IExternalSignInUserBuilder { - public async Task BuildNewUser(ApplicationUser user, ExternalLoginInfo externalLoginInfo) + public virtual async Task BuildNewUser(ApplicationUser user, ExternalLoginInfo externalLoginInfo) { if (user.MemberId is null && user.UserType == UserType.Customer.ToString()) { var contact = AbstractTypeFactory.TryCreateInstance(); - contact.Name = externalLoginInfo.Principal.FindFirstValue("name"); - contact.FirstName = externalLoginInfo.Principal.FindFirstValue(ClaimTypes.GivenName); - contact.LastName = externalLoginInfo.Principal.FindFirstValue(ClaimTypes.Surname); - contact.Emails = [user.Email]; + + contact.Name = ResolveContactName(user, externalLoginInfo); + contact.FirstName = ResolveContactFirstName(user, externalLoginInfo); + contact.LastName = ResolveContactLastName(user, externalLoginInfo); + contact.Emails = ResolveContactEmails(user, externalLoginInfo); if (!string.IsNullOrEmpty(user.StoreId)) { @@ -35,4 +37,24 @@ public async Task BuildNewUser(ApplicationUser user, ExternalLoginInfo externalL user.MemberId = contact.Id; } } + + protected virtual string ResolveContactName(ApplicationUser user, ExternalLoginInfo externalLoginInfo) + { + return externalLoginInfo.Principal.FindFirstValue("name"); + } + + protected virtual string ResolveContactFirstName(ApplicationUser user, ExternalLoginInfo externalLoginInfo) + { + return externalLoginInfo.Principal.FindFirstValue(ClaimTypes.GivenName) ?? string.Empty; + } + + protected virtual string ResolveContactLastName(ApplicationUser user, ExternalLoginInfo externalLoginInfo) + { + return externalLoginInfo.Principal.FindFirstValue(ClaimTypes.Surname) ?? string.Empty; + } + + protected virtual IList ResolveContactEmails(ApplicationUser user, ExternalLoginInfo externalLoginInfo) + { + return [user.Email]; + } }