public async Task <Account> RegisterExternalUser(ClaimsPrincipal principal, string location) { // add account & properties string updated_at = principal.FindFirst(ClaimTypes.UpdatedAt)?.Value; if (!DateTime.TryParse(updated_at, out DateTime lastUpdate)) { lastUpdate = DateTime.MinValue; } var subClaim = principal.FindFirst(ClaimTypes.Subject); var account = await _store.LoadByGuid(subClaim.Value); if (account == null) { account = new Data.Account { GlobalId = subClaim.Value, WhenCreated = DateTime.UtcNow, UpdatedAt = lastUpdate }; await _store.Add(account); await SetAccountNames(account, principal.FindFirst(ClaimTypes.Name)?.Value ?? "anonymous", false); UpdateProperty(account, "origin", subClaim.Issuer); UpdateExternalUserProfile(account, principal); } else { // sync props if (lastUpdate.CompareTo(account.UpdatedAt) > 0) { UpdateExternalUserProfile(account, principal); account.UpdatedAt = lastUpdate; } } return(await CompleteAuthentication(account, location)); }