Programmatic Auth Configs
Auth configs are created once and reused many times. However when dealing with many toolkits, you may want to create auth configs programmatically.
- When creating and destroying auth configs multiple times in your app’s lifecycle.
- When creating auth configs for your users’ users.
Using Composio Default Auth
For certain apps, you can optionally use Composio’s managed auth. This means you don’t have to provide your own OAuth credentials, Bearer tokens, API keys, etc.
The auth_config_id
should be stored securely in your database for future use to be created and destroyed multiple times.
You can also provide your own authentication details. The required credentials
and authScheme
depend on the auth type.
Using Custom Auth
Create the auth config
If you know the required authentication fields for your toolkit, you can directly create the auth config. OAuth2 is the most common auth type for apps. When using your own OAuth developer app, you must ensure to set the authorized redirect URI in the OAuth configuration to https://backend.composio.dev/api/v3/toolkits/callback
.
This is the URI that captures the OAuth code that is returned to the app.
In this case, we’re using our own OAuth2 client ID and secret to create the auth config for Notion:
Fetching the fields
For more complex cases where you need to dynamically discover the exact field names and handle different auth schemes programmatically, you can inspect the auth config details first.
Inspect the auth config details
Putting it all together
In this example, assuming you have the following environment variables set:
This makes it easy to create the auth config programmatically by reading required fields from the environment variables.