You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/server/new_blocks.md
+51-7Lines changed: 51 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,7 @@ for a service that we already have OAuth2 support for.
115
115
116
116
Implementing the block itself is relatively simple. On top of the instructions above,
117
117
you're going to add a `credentials` parameter to the `Input` model and the `run` method:
118
+
118
119
```python
119
120
from autogpt_libs.supabase_integration_credentials_store.types import (
120
121
APIKeyCredentials,
@@ -191,10 +192,12 @@ class BlockWithAPIKeyAndOAuth(Block):
191
192
) -> BlockOutput:
192
193
...
193
194
```
195
+
194
196
The credentials will be automagically injected by the executor in the back end.
195
197
196
198
The `APIKeyCredentials` and `OAuth2Credentials` models are defined [here](https://github.com/Significant-Gravitas/AutoGPT/blob/master/rnd/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/types.py).
197
199
To use them in e.g. an API request, you can either access the token directly:
As you can see, this is modeled after the standard OAuth2 flow.
237
245
238
246
Aside from implementing the `OAuthHandler` itself, adding a handler into the system requires two more things:
239
-
- Adding the handler class to `HANDLERS_BY_NAME`[here](https://github.com/Significant-Gravitas/AutoGPT/blob/master/autogpt_platform/backend/backend/integrations/oauth/__init__.py)
240
-
- Adding `{provider}_client_id` and `{provider}_client_secret` to the application's `Secrets`[here](https://github.com/Significant-Gravitas/AutoGPT/blob/e3f35d79c7e9fc6ee0cabefcb73e0fad15a0ce2d/autogpt_platform/backend/backend/util/settings.py#L132)
247
+
248
+
- Adding the handler class to `HANDLERS_BY_NAME` under [`integrations/oauth/__init__.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/master/autogpt_platform/backend/backend/integrations/oauth/__init__.py)
- Adding `{provider}_client_id` and `{provider}_client_secret` to the application's `Secrets` under [`util/settings.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/master/autogpt_platform/backend/backend/util/settings.py)
- GitHub blocks with API key + OAuth2 support: [`blocks/github`](https://github.com/Significant-Gravitas/AutoGPT/tree/master/autogpt_platform/backend/backend/blocks/github/)
- Google OAuth2 handler: [`integrations/oauth/google.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/master/autogpt_platform/backend/backend/integrations/oauth/google.py)
You can also see that `GOOGLE_OAUTH_IS_CONFIGURED` is used to disable the blocks that require OAuth if the oauth is not configured. This is in the `__init__` method of each block. This is because there is no api key fallback for google blocks so we need to make sure that the oauth is configured before we allow the user to use the blocks.
292
+
249
293
## Key Points to Remember
250
294
251
295
-**Unique ID**: Give your block a unique ID in the **init** method.
0 commit comments