Auto-link verified Google sign-ins by email
This commit is contained in:
@@ -135,6 +135,15 @@ public sealed class AuthController : ControllerBase
|
||||
x => x.GoogleSubject == google.Subject || (!string.IsNullOrWhiteSpace(google.Email) && x.GoogleEmail == google.Email),
|
||||
cancellationToken);
|
||||
|
||||
if (user is null && google.EmailVerified && !string.IsNullOrWhiteSpace(google.Email))
|
||||
{
|
||||
user = await _users.FindByEmailAsync(google.Email);
|
||||
if (user is not null)
|
||||
{
|
||||
_logger.LogInformation("Auto-linking Google sign-in for existing local account {Email}", google.Email);
|
||||
}
|
||||
}
|
||||
|
||||
if (user is null)
|
||||
{
|
||||
return Unauthorized("This Google account is not linked to a Jobbjakt user yet.");
|
||||
@@ -145,6 +154,9 @@ public sealed class AuthController : ControllerBase
|
||||
user.GoogleSubject = google.Subject;
|
||||
user.GoogleEmail = google.Email;
|
||||
user.GoogleLinkedAt ??= DateTimeOffset.UtcNow;
|
||||
user.DisplayName ??= TrimOrNull(google.Name);
|
||||
user.FirstName ??= TrimOrNull(google.GivenName);
|
||||
user.LastName ??= TrimOrNull(google.FamilyName);
|
||||
await _users.UpdateAsync(user);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user