Important: Store each grant_id in the application database, mapped to the user. This is how API calls are made later via vault.request(method, url, { grantId }). The grant_id is generated when the end user completes the OAuth flow — it is not something the developer creates.
Store account_identifier too (e.g., "[email protected]"). When a user connects multiple accounts to the same provider (personal + work Gmail), the account_identifier lets the application show a picker or set a default account per feature.
Omit allowed_providers to automatically show ALL providers configured in the Developer Portal:
app.post('/api/alter/session', async (req, res) => { const session = await vault.createConnectSession({ // No allowedProviders = show all configured providers }); res.json({ session_token: session.sessionToken });});
Best Practice: Configure providers in the Developer Portal, then omit allowed_providers in application code. This keeps provider management centralized and avoids hardcoding provider lists.
Security: Alter automatically filters requested providers to only those configured in the Developer Portal. Users cannot access unconfigured providers even if listed in allowed_providers.
await alterConnect.open({ token: session_token, onSuccess: async (connections) => { // Check that Google was connected const google = connections.find(c => c.provider === 'google'); if (!google) { alert('Please connect your Google account for calendar sync'); return; } for (const conn of connections) { await saveConnection(conn); } }});
await alterConnect.open({ token: session_token, onSuccess: async (connections) => { // Validate work email for all connections for (const conn of connections) { if (!conn.account_identifier.endsWith('@company.com')) { alert('Please use your @company.com work email'); return; } await saveConnection(conn); } }});