mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
refactor(docs): use better api logic
This commit is contained in:
parent
57f807a24f
commit
195f5160b4
|
@ -1,21 +1,39 @@
|
||||||
const axios = require('axios').default;
|
const axios = require('axios');
|
||||||
|
|
||||||
module.exports = async function (context, req) {
|
module.exports = async function (context, req) {
|
||||||
context.log('JavaScript HTTP trigger function processed a request.');
|
context.log('JavaScript HTTP trigger function processed a request.');
|
||||||
// http://www.strava.com/oauth/authorize?client_id=76033&response_type=code&redirect_uri=https://ohmyposh.dev/api/auth&approval_prompt=force&scope=read
|
// https://www.strava.com/oauth/authorize?client_id=76033&response_type=code&redirect_uri=https://ohmyposh.dev/api/auth&approval_prompt=force&scope=read,activity:read
|
||||||
|
|
||||||
const code = (req.query.code || (req.body && req.body.code));
|
try {
|
||||||
|
const code = (req.query._code || (req.body && req.body.code));
|
||||||
|
if (!code) {
|
||||||
|
context.res = {
|
||||||
|
status: 400
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var data = {
|
const params = {
|
||||||
client_id: process.env.STRAVA_CLIENT_ID,
|
client_id: process.env['STRAVA_CLIENT_ID'],
|
||||||
client_secret: process.env.STRAVA_CLIENT_SECRET,
|
client_secret: process.env['STRAVA_CLIENT_SECRET'],
|
||||||
code: code,
|
code: code,
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
};
|
};
|
||||||
const resp = await axios.post('https://www.strava.com/oauth/token', data);
|
const resp = await axios.post('https://www.strava.com/oauth/token', null, { params: params });
|
||||||
|
|
||||||
context.res = {
|
const body = {
|
||||||
// status: 200, /* Defaults to 200 */
|
access_token: resp.data.access_token,
|
||||||
body: resp.data
|
refresh_token: resp.data.refresh_token,
|
||||||
};
|
}
|
||||||
|
|
||||||
|
context.res = {
|
||||||
|
body: body
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
context.log(error);
|
||||||
|
context.res = {
|
||||||
|
body: error,
|
||||||
|
status: 500
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
16
docs/api/proxies.json
Normal file
16
docs/api/proxies.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/proxies",
|
||||||
|
"proxies": {
|
||||||
|
"callback": {
|
||||||
|
"matchCondition": {
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"route": "/api/auth"
|
||||||
|
},
|
||||||
|
"backendUri": "http://localhost/api/auth",
|
||||||
|
"requestOverrides": {
|
||||||
|
"backend.request.querystring.code": "",
|
||||||
|
"backend.request.querystring._code": "{request.querystring.code}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue