Skip to content

Commit

Permalink
feat: Add node js sample
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiehl committed Jan 22, 2024
1 parent 4268760 commit a123f00
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions secure_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const crypto = require('crypto');

const secret = 'mysecret';
const uri = '/my/uri';
const expire = '1470055000';

const md5 = crypto.createHash('md5');
md5.update((secret + uri + expire), 'utf-8');
const token = Buffer.from(md5.digest()).toString('base64').replace(/=|\+|\//g, (match) => ({
'=': '',
'+': '-',
'/': '_',
}[match]));

console.log(`http://www.example.org${uri}?st=${token}&e=${expire}`);

0 comments on commit a123f00

Please sign in to comment.