Skip to content

Instantly share code, notes, and snippets.

@fiveisprime
Last active August 29, 2015 13:56
Show Gist options
  • Save fiveisprime/8869130 to your computer and use it in GitHub Desktop.
Save fiveisprime/8869130 to your computer and use it in GitHub Desktop.
OAuth 1.0 nonce.
module.exports = function() {
const NONCE_CHARS = [
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1',
'2','3','4','5','6','7','8','9'
];
const NONCE_SIZE = 32;
return function() {
var result = [], position;
for (var i = 0; i < NONCE_SIZE; i++) {
position = Math.floor(Math.random() * NONCE_CHARS.length);
result[i] = NONCE_CHARS[position];
}
return result.join('');
};
};
@fiveisprime
Copy link
Author

var nonce = require('./nonce)();

console.log(nonce());

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