Skip to content

Commit

Permalink
fix: updated server for upload auth endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnv committed Jun 3, 2024
1 parent 03455e6 commit 0e0af55
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Server/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PRIVATE_KEY =
PUBLIC_KEY=
PRIVATE_KEY=
2 changes: 2 additions & 0 deletions Server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.lock
39 changes: 20 additions & 19 deletions Server/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
const dotenv = require('dotenv');
const express = require('express');
const router = express.Router();
var cors = require('cors');
const jwt = require('jsonwebtoken');
const app = express();
app.use(cors());
const cors = require('cors');

dotenv.config();

const uuid = require('uuid');
const crypto = require("crypto");
app.use(cors());
app.use(express.json());

const publicKey = process.env.PUBLIC_KEY;
const privateKey = process.env.PRIVATE_KEY;

router.get("/auth", function(req, res) {
var token = req.query.token || uuid.v4();
var expire = req.query.expire || parseInt(Date.now()/1000)+2400;
var privateAPIKey = `${privateKey}`;
var signature = crypto.createHmac('sha1', privateAPIKey).update(token+expire).digest('hex');
res.status(200);
res.send({
token : token,
expire : expire,
signature : signature
});
app.post("/auth", function (req, res) {
const token = jwt.sign(
req.body.uploadPayload,
privateKey,
{
expiresIn: req.body.expire,
header: {
alg: "HS256",
typ: "JWT",
kid: publicKey,
},
})
res.status(200);
res.send({ token });
});

app.use("/",router);

app.listen(8080,function(){
app.listen(8080, function () {
console.log("Live at Port 8080");
});
1 change: 1 addition & 0 deletions Server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^9.0.2",
"uuid": "^8.3.0"
}
}

0 comments on commit 0e0af55

Please sign in to comment.