Skip to content

Instantly share code, notes, and snippets.

@optlsnd
Last active March 17, 2023 07:09
Show Gist options
  • Save optlsnd/95ab117e2c022be633b452a4728889fa to your computer and use it in GitHub Desktop.
Save optlsnd/95ab117e2c022be633b452a4728889fa to your computer and use it in GitHub Desktop.
// Imports
const EdgeAuth = require("akamai-edgeauth");
// Configuration
const encryptionKey =
"73636b61519adede42191efe1e73f02a67c7b692e3765f90c250c230be095211";
const host = "sectest.ucarecdn.com";
const path = "/06933f0d-5f31-425d-a5b8-6c5c2cdaaae6/-/resize/600x/";
const duration = 3200;
// Generate token
const edgeAuth = new EdgeAuth({
key: encryptionKey,
windowSeconds: duration,
tokenName: "token",
escapeEarly: true,
});
const token = edgeAuth.generateACLToken(path);
const signedURL = `https://${host}${path}?${edgeAuth.options.tokenName}=${token}`;
console.log("Signed URL: ", signedURL);
@optlsnd
Copy link
Author

optlsnd commented Mar 17, 2023

Using wildcards:

// The token generated will apply to the original file and all its variations
const path = "/06933f0d-5f31-425d-a5b8-6c5c2cdaaae6/*";
// The token generated will apply to any file
const path = "*";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment