Skip to content

Commit

Permalink
add auth tokens as get params
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Oct 22, 2020
1 parent e2699e4 commit dc9608d
Show file tree
Hide file tree
Showing 5 changed files with 1,668 additions and 9 deletions.
8 changes: 8 additions & 0 deletions api/audio.js
Expand Up @@ -15,6 +15,14 @@ const redisClient = redis.createClient(
module.exports = async (req, res) => {
const params = query(req)

if (process.env.GET_AUTH_TOKEN) {
if (process.env.GET_AUTH_TOKEN !== params.token) {
micro.send(res, 401, "you do not have auth header")
} else if (!params.token) {
micro.send(res, 401, "you need to supply auth token")
}
}

if (!params.video_url) {
micro.send(res, 400, 'You forgot the "video_url", you idiot!')
return
Expand Down
10 changes: 10 additions & 0 deletions api/list-cache.js
Expand Up @@ -5,6 +5,16 @@ const redisClient = redis.createClient(
)

module.exports = async (req, res) => {
const params = query(req)

if (
process.env.GET_AUTH_TOKEN &&
process.env.GET_AUTH_TOKEN !== params.token
) {
micro.send(res, 401, "you do not have auth header")
return
}

const allKeys = await new Promise((resolve) => {
redisClient.keys("*", (err, keys) => {
if (err) {
Expand Down
8 changes: 8 additions & 0 deletions api/video.js
Expand Up @@ -16,6 +16,14 @@ module.exports = async (req, res) => {
const params = query(req)
const qualityLabel = params.quality || "480p"

if (
process.env.GET_AUTH_TOKEN &&
process.env.GET_AUTH_TOKEN !== params.token
) {
micro.send(res, 401, "you do not have auth header")
return
}

if (!params.video_url) {
micro.send(res, 400, 'You forgot the "video_url", you idiot!')
return
Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -9,11 +9,14 @@
"start:prod": "micro app.js"
},
"dependencies": {
"ava": "^3.13.0",
"axios": "^0.20.0",
"micro": "^9.3.4",
"micro-dev": "^3.0.0",
"micro-query": "^0.3.0",
"redis": "^3.0.2",
"rimraf": "^3.0.2",
"test-listen": "^1.1.0",
"tmp": "^0.2.1",
"ytdl-core": "^3.4.1"
}
Expand Down

0 comments on commit dc9608d

Please sign in to comment.