public void SyncInfo(IIdentity identity, CustomerContact currentContact, VippsSyncOptions options = default) { if (identity == null) { throw new ArgumentNullException(nameof(identity)); } if (currentContact == null) { throw new ArgumentNullException(nameof(currentContact)); } if (options == null) { options = new VippsSyncOptions(); } var vippsUserInfo = _vippsLoginService.GetVippsUserInfo(identity); if (vippsUserInfo == null) { return; } // Always sync vipps subject guid currentContact.SetVippsSubject(vippsUserInfo.Sub); if (options.SyncContactInfo) { // Maps fields onto customer contact // Vipps email, firstname, lastname, fullname, birthdate _vippsLoginMapper.MapVippsContactFields(currentContact, vippsUserInfo); } if (options.SyncAddresses && vippsUserInfo.Addresses != null) { foreach (var vippsAddress in vippsUserInfo.Addresses) { _vippsLoginMapper.MapAddress( currentContact, options.AddressType, vippsAddress, vippsUserInfo.PhoneNumber); } } if (options.ShouldSaveContact) { _customerContactService.SaveChanges(currentContact); } }
public bool HandleLogin( IOwinContext context, VippsSyncOptions vippsSyncOptions = default, CustomerContact customerContact = null) { var isAuthenticated = context.Authentication.User?.Identity?.IsAuthenticated ?? false; if (!isAuthenticated) { // Regular log in context.Authentication.Challenge(VippsAuthenticationDefaults.AuthenticationType); return(true); } // Make sure to sync vipps info (required for at least the identifier) // You can use the VippsSyncOptions to determine what else to sync (contact/address info) SyncInfo( context.Authentication.User.Identity, customerContact ?? CustomerContext.Current.CurrentContact, vippsSyncOptions); return(false); }