-
Notifications
You must be signed in to change notification settings - Fork 44.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): OAuth support + API key management + GitHub blocks (#…
…8044) ## Config - For Supabase, the back end needs `SUPABASE_URL`, `SUPABASE_SERVICE_ROLE_KEY`, and `SUPABASE_JWT_SECRET` - For the GitHub integration to work, the back end needs `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` - For integrations OAuth flows to work in local development, the back end needs `FRONTEND_BASE_URL` to generate login URLs with accurate redirect URLs ## REST API - Tweak output of OAuth `/login` endpoint: add `state_token` separately in response - Add `POST /integrations/{provider}/credentials` (for API keys) - Add `DELETE /integrations/{provider}/credentials/{cred_id}` ## Back end - Add Supabase support to `AppService` - Add `FRONTEND_BASE_URL` config option, mainly for local development use ### `autogpt_libs.supabase_integration_credentials_store` - Add `CredentialsType` alias - Add `.bearer()` helper methods to `APIKeyCredentials` and `OAuth2Credentials` ### Blocks - Add `CredentialsField(..) -> CredentialsMetaInput` ## Front end ### UI components - `CredentialsInput` for use on `CustomNode`: allows user to add/select credentials for a service. - `APIKeyCredentialsModal`: a dialog for creating API keys - `OAuth2FlowWaitingModal`: a dialog to indicate that the application is waiting for the user to log in to the 3rd party service in the provided pop-up window - `NodeCredentialsInput`: wrapper for `CredentialsInput` with the "usual" interface of node input components - New icons: `IconKey`, `IconKeyPlus`, `IconUser`, `IconUserPlus` ### Data model - `CredentialsProvider`: introduces the app-level `CredentialsProvidersContext`, which acts as an application-wide store and cache for credentials metadata. - `useCredentials` for use on `CustomNode`: uses `CredentialsProvidersContext` and provides node-specific credential data and provider-specific data/functions - `/auth/integrations/oauth_callback` route to close the loop to the `CredentialsInput` after a user completes sign-in to the external service - Add `BlockIOCredentialsSubSchema` ### API client - Add `isAuthenticated` method - Add methods for integration OAuth flow: `oAuthLogin`, `oAuthCallback` - Add CRD methods for credentials: `createAPIKeyCredentials`, `listCredentials`, `getCredentials`, `deleteCredentials` - Add mirrored types `CredentialsMetaResponse`, `CredentialsMetaInput`, `OAuth2Credentials`, `APIKeyCredentials` - Add GitHub blocks + "DEVELOPER_TOOLS" category - Add `**kwargs` to `Block.run(..)` signature to support additional kwargs - Add support for loading blocks from nested modules (e.g. `blocks/github/issues.py`) #### Executor - Add strict support for `credentials` fields on blocks - Fetch credentials for graph execution and pass them down through to the node execution
- Loading branch information
Showing
51 changed files
with
3,689 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import Literal | ||
|
||
from autogpt_libs.supabase_integration_credentials_store.types import ( | ||
APIKeyCredentials, | ||
OAuth2Credentials, | ||
) | ||
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"] if GITHUB_OAUTH_IS_CONFIGURED else Literal["api_key"], | ||
] | ||
|
||
|
||
def GithubCredentialsField(scope: str) -> GithubCredentialsInput: | ||
""" | ||
Creates a GitHub credentials input on a block. | ||
Params: | ||
scope: The authorization scope needed for the block to work. ([list of available scopes](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes)) | ||
""" # noqa | ||
return CredentialsField( | ||
provider="github", | ||
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.", | ||
) | ||
|
||
|
||
TEST_CREDENTIALS = APIKeyCredentials( | ||
id="01234567-89ab-cdef-0123-456789abcdef", | ||
provider="github", | ||
api_key=SecretStr("mock-github-api-key"), | ||
title="Mock GitHub API key", | ||
expires_at=None, | ||
) | ||
TEST_CREDENTIALS_INPUT = { | ||
"provider": TEST_CREDENTIALS.provider, | ||
"id": TEST_CREDENTIALS.id, | ||
"type": TEST_CREDENTIALS.type, | ||
"title": TEST_CREDENTIALS.type, | ||
} |
Oops, something went wrong.