OAuth lets your users authorize access to their accounts on services like Slack, GitHub, Google Calendar, and more. This enables your AI agents to perform actions on behalf of your users with their explicit permission.
How OAuth works
The OAuth flow uses Provider Setup Sessions:
Create a Provider Setup Session for the provider the user needs to authorize
Redirect the user to the session URL to complete OAuth in their browser
Wait for completion — returns the completed setup session with an auth config
Store the Provider Auth Config ID for that user in your database
Pass the auth config ID when creating sessions for that user
Creating provider setup sessions
let setupSession = await metorial.providerDeployments.setupSessions.create({ providerId: 'your-provider-id', providerAuthMethodId: 'oauth', // Optional: specify deployment if you have multiple for the same provider // providerDeploymentId: 'your-deployment-id', // Optional: redirect user here after authorizing // callbackUri: 'https://yourapp.com/oauth/callback'});// Redirect your user to this URLconsole.log('Authorize here:', setupSession.url);
Waiting for completion
// Waits until the user completes OAuth — returns the completed setup sessionslet completed = await metorial.providerDeployments.setupSessions.waitForCompletion([setupSession]);// Store the auth config ID for this userawait db.users.update(userId, { slackAuthConfigId: completed[0]!.authConfig!.id});
Using auth configs in sessions
Retrieve the stored auth config ID from your database and pass it when creating a session: