Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config options to automatically activate accounts from GitHub, email or any auth source #822

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pydatalab/pydatalab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ class ServerConfig(BaseSettings):
description="Whether to automatically activate accounts created via ORCID registration.",
)

GITHUB_AUTO_ACTIVATE_ACCOUNTS: bool = Field(
False,
description="Whether to automatically activate accounts created via GitHub registration.",
)

EMAIL_AUTO_ACTIVATE_ACCOUNTS: bool = Field(
False,
description="Whether to automatically activate accounts created via email registration.",
)

AUTO_ACTIVATE_ACCOUNTS: bool = Field(
False,
description="Whether to automatically activate accounts created via any registration method.",
)

EMAIL_DOMAIN_ALLOW_LIST: Optional[List[str]] = Field(
[],
description="A list of domains for which users will be able to register accounts if they have a matching verified email address, which still need to be verified by an admin. Setting the value to `None` will allow any email addresses at any domain to register *and activate* an account, otherwise the default `[]` will not allow any email addresses registration.",
Expand Down
11 changes: 9 additions & 2 deletions pydatalab/pydatalab/routes/v0_1/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ def email_logged_in():
raise UserRegistrationForbidden

create_account = AccountStatus.UNVERIFIED
if CONFIG.EMAIL_DOMAIN_ALLOW_LIST is None:
if (
CONFIG.EMAIL_DOMAIN_ALLOW_LIST is None
or CONFIG.EMAIL_AUTO_ACTIVATE_ACCOUNTS
or CONFIG.AUTO_ACTIVATE_ACCOUNTS
):
create_account = AccountStatus.ACTIVE

find_create_or_modify_user(
Expand Down Expand Up @@ -426,6 +430,9 @@ def github_logged_in(blueprint, token):
elif CONFIG.GITHUB_ORG_ALLOW_LIST is None:
create_account = True

if CONFIG.GITHUB_AUTO_ACTIVATE_ACCOUNTS or CONFIG.AUTO_ACTIVATE_ACCOUNTS:
create_account = AccountStatus.ACTIVE

find_create_or_modify_user(
github_user_id,
IdentityType.GITHUB,
Expand All @@ -452,7 +459,7 @@ def orcid_logged_in(_, token):

# New ORCID accounts must be activated by an admin unless configured otherwise
create_account = AccountStatus.UNVERIFIED
if CONFIG.ORCID_AUTO_ACTIVATE_ACCOUNTS:
if CONFIG.ORCID_AUTO_ACTIVATE_ACCOUNTS or CONFIG.AUTO_ACTIVATE_ACCOUNTS:
create_account = AccountStatus.ACTIVE

find_create_or_modify_user(
Expand Down
Loading