-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuppeteer.js
More file actions
40 lines (32 loc) · 1.36 KB
/
puppeteer.js
File metadata and controls
40 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import puppeteer from 'puppeteer';
import dotenv from 'dotenv';
dotenv.config();
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Navigate to the login page
await page.goto(`https://developer.digitail.io/oauth/authorize?client_id=${process.env.CLIENT_ID}&redirect_uri=${process.env.REDIRECT_URL}&response_type=code&scope=`);
// Fill in the login form
// await page.type('#username', 'YOUR_USERNAME');
// await page.type('#password', 'YOUR_PASSWORD');
// Submit the form
// await page.click('#submit_button_id');
// Wait for navigation to the redirect URI
await page.waitForNavigation();
// The page URL should contain 'code='
const url = page.url();
const code = new URL(url).searchParams.get('code');
if (code) {
console.log('Authorization Code:', code);
// Now you can use the authorization code to get an access token
const tokenResponse = await axios.post('https://developer.digitail.io/oauth/token', {
client_id: 'YOUR_CLIENT_ID',
client_secret: 'YOUR_CLIENT_SECRET',
redirect_uri: 'http://localhost:3000/callback',
grant_type: 'authorization_code',
code: code,
});
console.log('Access Token:', tokenResponse.data.access_token);
}
await browser.close();
})();