public async Task <AuthenticateUserResult> AuthenticateExternalUserAsync( AuthenticateExternalUserRequest request, CancellationToken cancellationToken) { User?user = await _userRepository.TryGetUserByProvider( request.Provider, request.UserIdentifier, cancellationToken); if (user != null) { return(new AuthenticateUserResult(true) { User = user }); } else { if (_options.AutoProvisionUser) { user = _userFactory.CreateFromExternalLogin( request.Provider, request.UserIdentifier, request.Claims); user.LastLogin = DateTime.UtcNow; await _userRepository.AddAsync(user, cancellationToken); return(new AuthenticateUserResult(true) { User = user }); } } return(new AuthenticateUserResult(false)); }