Use this file to discover all available pages before exploring further.
Use OAuth when the API you’re connecting to requires user authorization, such as GitHub, Google, Salesforce, and most SaaS APIs. You register an OAuth capability on your worker, deploy, complete the authorization flow via the CLI, and then call accessToken() in your code to get a valid token.
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).
ntn workers deploy
2
Get your redirect URL
ntn workers oauth show-redirect-url
You’ll need this when creating the OAuth app with your provider.
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
ntn workers env set GITHUB_CLIENT_ID=xxx GITHUB_CLIENT_SECRET=yyy
5
Deploy again
Redeploy so the worker picks up the credentials:
ntn workers deploy
6
Start the OAuth flow
ntn workers oauth start githubAuth
This opens a browser window where you authorize the connection. Once complete, the worker runtime stores the token securely.
Once you’ve completed the OAuth flow (via ntn workers oauth start), pull your environment to get a fresh access token locally:
ntn workers env pull
This writes a .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:
ntn workers exec getGitHubRepos --local
OAuth tokens expire. If you get a 401 from the provider, run ntn workers env pull again to get a refreshed token.
Some providers (like Salesforce) don’t return expires_in in their token response. Set accessTokenExpireMs to a sensible default (e.g., 3600000 for 1 hour) so the runtime knows when to refresh.