-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtokentest.js
33 lines (29 loc) · 1.2 KB
/
tokentest.js
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
const axios = require('axios');
const config = require('./config-global');
const checkToken = async (url, token, tokenType) => {
try {
const response = await axios.get(url, {
headers: { 'Authorization': `${tokenType} ${token}` }
});
console.log(`${tokenType} token is valid:`, response.data);
} catch (error) {
console.error(`${tokenType} token is invalid:`, error.response ? error.response.data : error.message);
}
};
const checkReportWebhookUrl = async () => {
try {
const response = await axios.post(config.REPORT_WEBHOOK_URL, {
content: 'Test message to verify the tokens in the code'
});
console.log('Report webhook URL is valid:', response.data);
} catch (error) {
console.error('Report webhook URL is invalid:', error.response ? error.response.data : error.message);
}
};
const runTests = async () => {
await checkToken('https://api.github.com/user', config.GITHUB_TOKEN, 'Bearer');
await checkToken('https://discord.com/api/v10/users/@me', config.TOKEN, 'Bot');
await checkToken(`${config.MEME_API_URL}?api-key=${config.MEME_API_KEY}`, '', '');
await checkReportWebhookUrl();
};
runTests();