/** * OAuth2 Authorization Code Flow Implementation * * This module implements a complete OAuth2 authorization code flow for Flowise credentials. * It supports Microsoft Graph and other OAuth2 providers. * * CREDENTIAL DATA STRUCTURE: * The credential's encryptedData should contain a JSON object with the following fields: * * Required fields: * - client_id: OAuth2 application client ID * - client_secret: OAuth2 application client secret * * Optional fields (provider-specific): * - tenant_id: Microsoft Graph tenant ID (if using Microsoft Graph) * - authorization_endpoint: Custom authorization URL (defaults to Microsoft Graph if tenant_id provided) * - token_endpoint: Custom token URL (defaults to Microsoft Graph if tenant_id provided) * - redirect_uri: Custom redirect URI (defaults to this callback endpoint) * - scope: OAuth2 scopes to request (e.g., "user.read mail.read") * - response_type: OAuth2 response type (defaults to "code") * - response_mode: OAuth2 response mode (defaults to "query") * * ENDPOINTS: * * 1. POST /api/v1/oauth2/authorize/:credentialId * - Generates authorization URL for initiating OAuth2 flow * - Uses credential ID as state parameter for security * - Returns authorization URL to redirect user to * * 2. GET /api/v1/oauth2/callback * - Handles OAuth2 callback with authorization code * - Exchanges code for access token * - Updates credential with token data * - Supports Microsoft Graph and custom OAuth2 providers * * 3. POST /api/v1/oauth2/refresh/:credentialId * - Refreshes expired access tokens using refresh token * - Updates credential with new token data * * USAGE FLOW: * 1. Create a credential with OAuth2 configuration (client_id, client_secret, etc.) * 2. Call POST /oauth2/authorize/:credentialId to get authorization URL * 3. Redirect user to authorization URL * 4. User authorizes and gets redirected to callback endpoint * 5. Callback endpoint exchanges code for tokens and saves them * 6. Use POST /oauth2/refresh/:credentialId when tokens expire * * TOKEN STORAGE: * After successful authorization, the credential will contain additional fields: * - access_token: OAuth2 access token * - refresh_token: OAuth2 refresh token (if provided) * - token_type: Token type (usually "Bearer") * - expires_in: Token lifetime in seconds * - expires_at: Token expiry timestamp (ISO string) * - granted_scope: Actual scopes granted by provider * - token_received_at: When token was received (ISO string) */ declare const router: import("express-serve-static-core").Router; export default router;