diff --git a/endpoints/callbacks.py b/endpoints/callbacks.py index 66bb79f08..a8bb05dbe 100644 --- a/endpoints/callbacks.py +++ b/endpoints/callbacks.py @@ -84,8 +84,15 @@ def conduct_oauth_login(service, user_id, username, email, metadata={}): # Try to create the user try: - valid = next(generate_valid_usernames(username)) - to_login = model.create_federated_user(valid, email, service_name.lower(), + new_username = None + for valid in generate_valid_usernames(username): + if model.get_user_or_org(valid): + continue + + new_username = valid + break + + to_login = model.create_federated_user(new_username, email, service_name.lower(), user_id, set_password_notification=True, metadata=metadata)