accessToken() in your code to get a valid token.
Define an OAuth capability
Callworker.oauth() with your provider’s OAuth 2.0 endpoints and credentials:
src/index.ts
Configuration options
Deploy and authorize
Setting up OAuth requires multiple steps in a specific order. The worker must be deployed before you can store secrets or start the OAuth flow:1
Deploy your worker
If you haven’t deployed at least once already, do so first. The first deploy registers the worker with Notion. Your OAuth credentials won’t be available yet (that’s expected).
2
Get your redirect URL
3
Create an OAuth app with your provider
Go to your provider’s developer settings (e.g., GitHub Developer Settings, Google Cloud Console) and create an OAuth app. Add the redirect URL from the previous step as an authorized redirect URI. Copy the client ID and client secret.
4
Store your OAuth credentials
5
Deploy again
Redeploy so the worker picks up the credentials:
6
Start the OAuth flow
Use the token
CallaccessToken() on the OAuth capability object to get a valid token. The runtime handles refresh automatically. This works in tools, syncs, and webhooks:
Test locally
Once you’ve completed the OAuth flow (viantn workers oauth start), pull your environment to get a fresh access token locally:
.env file with all your worker’s secrets, including a fresh OAuth access token. The server refreshes the token automatically before returning it, so the token you get is always valid.
You can then test your capability locally with the --local flag:
OAuth tokens expire. If you get a 401 from the provider, run
ntn workers env pull again to get a refreshed token.Examples
Salesforce
Next steps
Secrets
Store API keys and OAuth credentials securely.
Syncs
Sync external data into Notion databases.
Webhooks
Receive HTTP events from external services.