Skip to content

Commit

Permalink
Disable GitHub OAuth on blocks if not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Sep 25, 2024
1 parent 31bdd34 commit 1e3ddec
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions autogpt_platform/backend/backend/blocks/github/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
from pydantic import SecretStr

from backend.data.model import CredentialsField, CredentialsMetaInput
from backend.util.settings import Secrets

secrets = Secrets()
GITHUB_OAUTH_IS_CONFIGURED = bool(
secrets.github_client_id and secrets.github_client_secret
)

GithubCredentials = APIKeyCredentials | OAuth2Credentials
GithubCredentialsInput = CredentialsMetaInput[
Literal["github"], Literal["api_key", "oauth2"]
Literal["github"],
Literal["api_key", "oauth2"] if GITHUB_OAUTH_IS_CONFIGURED else Literal["api_key"],
]


Expand All @@ -23,7 +30,9 @@ def GithubCredentialsField(scope: str) -> GithubCredentialsInput:
""" # noqa
return CredentialsField(
provider="github",
supported_credential_types={"api_key", "oauth2"},
supported_credential_types=(
{"api_key", "oauth2"} if GITHUB_OAUTH_IS_CONFIGURED else {"api_key"}
),
required_scopes={scope},
description="The GitHub integration can be used with OAuth, "
"or any API key with sufficient permissions for the blocks it is used on.",
Expand Down

0 comments on commit 1e3ddec

Please sign in to comment.