public virtual void AddOrUpdateExternalLogin(UserAccount account, string provider, string id, IEnumerable <Claim> claims = null) { if (account == null) { throw new ArgumentNullException(nameof(account)); } _logger.LogInformation(GetLogMessage($"called for accountId: {account.UserId}")); if (string.IsNullOrWhiteSpace(provider)) { _logger.LogError(GetLogMessage("failed -- null provider")); throw new ArgumentNullException(nameof(provider)); } if (string.IsNullOrWhiteSpace(id)) { _logger.LogError(GetLogMessage("failed -- null id")); throw new ArgumentNullException(nameof(id)); } var otherAcct = GetByExternalLogin(provider, id); if (otherAcct != null && otherAcct.UserId != account.UserId) { _logger.LogError(GetLogMessage("failed -- adding linked account that is already associated with another account")); throw new ValidationException(GetValidationMessage("ExternalLoginAlreadyInUse")); } //RemoveExternalLoginClaims(account, provider, id); var linked = GetExternalLogin(account, provider, id); if (linked == null) { linked = new ExternalLogin { LoginProvider = provider, ProviderKey = id, LastLogin = UtcNow }; account.AddExternalLogin(linked); AddEvent(new ExternalLoginAddedEvent { Account = account, ExternalLogin = linked }); _logger.LogTrace(GetLogMessage("linked account added")); } else { linked.LastLogin = UtcNow; } account.LastLogin = UtcNow; Update(account); }