Skip to content

Instantly share code, notes, and snippets.

// The Auth0 client ID
const AUTH0_CLIENT_ID = "PUT-YOUR-CLIENT-ID-HERE"
// The Auth0 domain
const AUTH0_DOMAIN = "PUT-YOUR-DOMAIN-HERE"
config.auth0Domain = "PUT-YOUR-DOMAIN-HERE"
config.serverHostName = "PUT-YOUR-SERVER-HOSTNAME-HERE"
// Just use the static secret during HMAC verification for this demo stage
hmac = crypto.createHmac('sha256', Buffer.from(secret, 'base64'))
...
...
// Compute the request HMAC using the HMAC SHA-256 algorithm
hmac.update(req.protocol)
hmac.update(req.host)
hmac.update(req.originalUrl)
hmac.update(req.get('Authorization'))
var ourShipFastHMAC = hmac.digest('hex')
// Retrieve the ShipFast HMAC used to sign the API request from the request header
var requestShipFastHMAC = req.get('SF-HMAC')
// The ShipFast HMAC secret used to sign API requests
const SHIPFAST_HMAC_SECRET = '4ymoofRe0l87QbGoR0YH+/tqBN933nKAGxzvh5z2aXr5XlsYzlwQ6pVArGweqb7cN56khD/FvY0b6rWc4PFOPw=='
// The current demo stage
config.currentDemoStage = DEMO_STAGE.HMAC_STATIC_SECRET_PROTECTION
/** The current demo stage */
val currentDemoStage = DemoStage.HMAC_STATIC_SECRET_PROTECTION
for (var lat = latStart; lat <= latEnd; lat += locStep) {
for (var lon = lonStart; lon <= lonEnd; lon += locStep) {
fetchNearestShipment(lat, lon)
}
}
// Create middleware for checking the JWT
const checkJwt = jwt({
// Dynamically provide a signing key based on the kid in the header and the singing keys provided by the JWKS endpoint
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: "https://" + config.auth0Domain + "/.well-known/jwks.json"
}),