-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsso.js
32 lines (28 loc) · 883 Bytes
/
sso.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
const axios = require('axios');
async function getAccessToken(authCode) {
const tokenUrl = 'https://api.ivao.aero/v2/oauth/token';
const response = await axios.post(tokenUrl, {
grant_type: 'authorization_code',
code: authCode,
redirect_uri: 'http://localhost:3000/callback',
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET
});
return response.data.access_token;
}
async function getCurrentATCPosition(accessToken) {
try {
const session = await axios.get('https://api.ivao.aero/v2/users/me/sessions/now', {
headers: { Authorization: `Bearer ${accessToken}` }
});
return session.data.callsign
} catch (error) {
if (error.status == 404) {
return ""
}
}
}
module.exports = {
getAccessToken,
getCurrentATCPosition
};