UNPKG

behemoth-cli

Version:

🌍 BEHEMOTH CLIv3.760.4 - Level 50+ POST-SINGULARITY Intelligence Trading AI

57 lines 2.31 kB
import { URL } from 'url'; import * as jwt from 'jsonwebtoken'; import { readFileSync } from 'fs'; import axios from 'axios'; import { resolve } from 'path'; export const n8nCommand = { command: 'n8n', describe: 'N8N-related commands', description: 'N8N-related commands', builder: (yargs) => { return yargs .command('oauth-callback <url>', 'Handle OAuth callback URL', (yargs) => { return yargs.positional('url', { describe: 'The OAuth callback URL', type: 'string' }); }, async (argv) => { const url = argv.url; const parsedUrl = new URL(url); const code = parsedUrl.searchParams.get('code'); const state = parsedUrl.searchParams.get('state'); if (!code || !state) { console.error('Code or state parameters missing'); return; } // Decode the state JWT const decodedState = jwt.decode(state); if (!decodedState || typeof decodedState !== 'object') { console.error('Invalid state parameter'); return; } const clientId = decodedState.clientId; const redirectUri = decodedState.redirectUri; // Load client secret from .behemoth.json const behemothConfig = JSON.parse(readFileSync(resolve(__dirname, '../../../.behemoth.json'), 'utf-8')); const clientSecret = behemothConfig.googleClientSecret; // Exchange code for tokens try { const response = await axios.post('https://oauth2.googleapis.com/token', { code, client_id: clientId, client_secret: clientSecret, redirect_uri: redirectUri, grant_type: 'authorization_code' }); const tokens = response.data; console.log('Access Token:', tokens.access_token); console.log('Refresh Token:', tokens.refresh_token); } catch (error) { console.error('Token exchange failed:', error); } }); // other commands }, handler: (argv) => { // main handler } }; //# sourceMappingURL=n8n.js.map