Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding experiment name to hmac #50

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions encode-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require("dotenv").config()
const secretKey = process.env.SECRET_KEY
const experimentId = "public_goods_game"
const users = [212035, 212036, 212037, 212038, 212039, 212040]
const host = "localhost:8060"
if (!secretKey) {
console.log("[ERROR] no secret key")
return
Expand All @@ -15,10 +16,10 @@ function getYmdDate() {
}
const now = getYmdDate()
users.forEach((u) => {
const dataToSign = `${u}${now}`
const dataToSign = `${u}:${now}:${experimentId.toLowerCase()}`
const signatureWordArray = CryptoJS.HmacSHA256(dataToSign, secretKey)
const signatureHex = CryptoJS.enc.Hex.stringify(signatureWordArray)
console.log(
`http://localhost:8060/room/${experimentId}?respondent=${u}&check=${signatureHex}`,
`http://${host}/room/${experimentId}?respondent=${u}&check=${signatureHex}`,
)
})
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ const validateHmac = (req, res, next) => {

const respondent = req.query.respondent
const check = req.query.check
const experimentId = req.params.experimentId

const dataToSign = `${respondent}${today}`
const dataToSign = `${respondent}:${today}:${experimentId}`
console.log(dataToSign)
console.log(secretKey)
const signatureWordArray = CryptoJS.HmacSHA256(dataToSign, secretKey)
Expand Down