feat: preliminary auth for strava

This commit is contained in:
Jan De Dobbeleer 2022-01-04 09:39:45 +01:00 committed by Jan De Dobbeleer
parent d59ab5e4e0
commit 2c35779900
3 changed files with 78 additions and 11 deletions

View file

@ -1,13 +1,21 @@
const axios = require('axios').default;
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
const name = (req.query.name || (req.body && req.body.name));
const responseMessage = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
const code = (req.query.code || (req.body && req.body.code));
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
var data = {
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/oauth/token', data);
context.res = {
// status: 200, /* Defaults to 200 */
body: resp.data
};
}

58
docs/api/package-lock.json generated Normal file
View file

@ -0,0 +1,58 @@
{
"name": "api",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "api",
"version": "1.0.0",
"dependencies": {
"axios": "^0.24.0"
},
"devDependencies": {}
},
"node_modules/axios": {
"version": "0.24.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
"dependencies": {
"follow-redirects": "^1.14.4"
}
},
"node_modules/follow-redirects": {
"version": "1.14.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz",
"integrity": "sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
}
},
"dependencies": {
"axios": {
"version": "0.24.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
"requires": {
"follow-redirects": "^1.14.4"
}
},
"follow-redirects": {
"version": "1.14.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz",
"integrity": "sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A=="
}
}
}

View file

@ -6,6 +6,7 @@
"start": "func start",
"test": "echo \"No tests yet...\""
},
"dependencies": {},
"devDependencies": {}
"dependencies": {
"axios": "^0.24.0"
}
}