oh-my-posh/website/api/shared/strava.js

39 lines
1 KiB
JavaScript
Raw Normal View History

2022-01-06 12:19:21 -08:00
const axios = require('axios');
2022-07-11 05:41:50 -07:00
async function getToken(code) {
2022-01-06 12:19:21 -08:00
const params = {
client_id: process.env['STRAVA_CLIENT_ID'],
client_secret: process.env['STRAVA_CLIENT_SECRET'],
code: code,
grant_type: 'authorization_code',
};
const resp = await axios.post('https://www.strava.com/api/v3/oauth/token', null, { params: params });
return {
2022-01-06 12:19:21 -08:00
access_token: resp.data.access_token,
refresh_token: resp.data.refresh_token,
expires_in: resp.data.expires_in
};
2022-01-06 12:19:21 -08:00
}
2022-07-11 05:41:50 -07:00
async function refreshToken(refresh_token) {
2022-01-06 12:19:21 -08:00
const params = {
client_id: process.env['STRAVA_CLIENT_ID'],
client_secret: process.env['STRAVA_CLIENT_SECRET'],
refresh_token: refresh_token,
grant_type: 'refresh_token',
};
const resp = await axios.post('https://www.strava.com/api/v3/oauth/token', null, { params: params });
return {
2022-01-06 12:19:21 -08:00
access_token: resp.data.access_token,
refresh_token: resp.data.refresh_token,
expires_in: resp.data.expires_in
};
2022-01-06 12:19:21 -08:00
}
module.exports = {
2022-07-11 05:41:50 -07:00
getToken: getToken,
refreshToken: refreshToken,
2022-01-06 12:19:21 -08:00
}