@vonage/auth
Advanced tools
Comparing version 3.0.0-beta.0 to 3.0.0-beta.4
@@ -1,2 +0,2 @@ | ||
import { AuthConstructor } from './common'; | ||
import { AuthConstructor } from './types'; | ||
export declare const Auth: AuthConstructor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Auth = void 0; | ||
const crypto_1 = require("crypto"); | ||
const types_1 = require("./types"); | ||
const Auth = class Auth { | ||
constructor(opts) { | ||
// add additional methods to find auth | ||
// also needs to handle private key, signatures, etc | ||
// also needs to handle private key, etc | ||
this.getQueryParams = (params) => { | ||
return Object.assign({ api_key: this.apiKey, api_secret: this.apiSecret }, params); | ||
}; | ||
this.createSignatureHash = (params) => { | ||
let returnParams = Object.assign({ api_key: this.apiKey }, params); | ||
// Add the current timestamp to the parameters list with the key 'timestamp'. | ||
// This should be an integer containing the number of seconds since the epoch (UNIX time)) | ||
returnParams['timestamp'] = Math.floor(Date.now() / 1000).toString(); | ||
// Loop through each of the parameters, sorted by key. | ||
// For every value in the parameter list, replace all instances of & and = with an underscore _. | ||
let keys = Object.keys(returnParams); | ||
let stringifiedParamsforSigning = keys.sort().map((keyName) => { | ||
// Generate a string consisting of &akey=value | ||
return `&${keyName}=${returnParams[keyName].toString().replace(/(&|=)/ig, '_')}`; | ||
}, []).join(''); | ||
// For hash | ||
// Add signature secret to the end of the string, directly after the last value. | ||
// It should now look something like this: '&akey=value&bkey=value${your_signature_secret}' | ||
// Now run the string through an md5 hash function | ||
// convert the resulting bytes to a string of hexadecimal digits. | ||
// This is your MD5 hash signature, | ||
// Should be added to the HTTP parameters of your request as the 'sig' parameter. | ||
if (this.signature.algorithm === types_1.AlgorithmTypes.md5hash) { | ||
returnParams['sig'] = (0, crypto_1.createHash)('md5').update(stringifiedParamsforSigning + this.signature.secret).digest('hex'); | ||
} | ||
// For HMAC | ||
// Create an HMAC generator with your desired algorithm and your signature secret as the key. | ||
// Now run the string through an hmac generator | ||
// convert the resulting bytes to a string of hexadecimal digits. | ||
// This is your HMAC signature, | ||
// Should be added to the HTTP parameters of your request as the sig parameter | ||
if (this.signature.algorithm === types_1.AlgorithmTypes.md5hmac) { | ||
returnParams['sig'] = (0, crypto_1.createHmac)('md5', this.signature.secret).update(stringifiedParamsforSigning).digest('hex'); | ||
} | ||
if (this.signature.algorithm === types_1.AlgorithmTypes.sha1hmac) { | ||
returnParams['sig'] = (0, crypto_1.createHmac)('sha1', this.signature.secret).update(stringifiedParamsforSigning).digest('hex'); | ||
} | ||
if (this.signature.algorithm === types_1.AlgorithmTypes.sha256hmac) { | ||
returnParams['sig'] = (0, crypto_1.createHmac)('sha256', this.signature.secret).update(stringifiedParamsforSigning).digest('hex'); | ||
} | ||
if (this.signature.algorithm === types_1.AlgorithmTypes.sha512hmac) { | ||
returnParams['sig'] = (0, crypto_1.createHmac)('sha512', this.signature.secret).update(stringifiedParamsforSigning).digest('hex'); | ||
} | ||
return returnParams; | ||
}; | ||
this.apiKey = (opts === null || opts === void 0 ? void 0 : opts.apiKey) || ''; | ||
this.apiSecret = (opts === null || opts === void 0 ? void 0 : opts.apiSecret) || ''; | ||
this.signature = (opts === null || opts === void 0 ? void 0 : opts.signature) || null; | ||
} | ||
getQueryParams() { | ||
return { api_key: this.apiKey, api_secret: this.apiSecret }; | ||
} | ||
}; | ||
exports.Auth = Auth; | ||
// loop through ordered data keys here, | ||
// keys.on('readable', () => { | ||
// // Only one element is going to be produced by the | ||
// // hash stream. | ||
// const data = input.read(); | ||
// if (data) | ||
// hash.update(data); | ||
// else { | ||
// console.log(`${hash.digest('hex')} ${filename}`); | ||
// } | ||
// }); |
import { Auth } from './auth'; | ||
export { AuthConstructor, AuthInterface, AuthQueryParams, AuthOpts, } from './common'; | ||
export { AuthConstructor, AuthInterface, AuthQueryParams, AuthOpts, AlgorithmTypes, SignedHashParams, AuthSignedParams } from './types'; | ||
export { Auth }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Auth = void 0; | ||
exports.Auth = exports.AlgorithmTypes = void 0; | ||
const auth_1 = require("./auth"); | ||
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return auth_1.Auth; } }); | ||
var types_1 = require("./types"); | ||
Object.defineProperty(exports, "AlgorithmTypes", { enumerable: true, get: function () { return types_1.AlgorithmTypes; } }); |
{ | ||
"name": "@vonage/auth", | ||
"version": "3.0.0-beta.0", | ||
"version": "3.0.0-beta.4", | ||
"description": "> TODO: description", | ||
@@ -24,9 +24,16 @@ "author": "Kelly J Andrews <kelly@kellyjandrews.com>", | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.3.5" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Vonage/vonage-node-sdk/issues" | ||
}, | ||
"gitHead": "4e5d884ae9aea22c6cb8149a712fd8d56a7dcb39" | ||
"gitHead": "391f630bd790311fa52eaa15391cad97eccdd7ad", | ||
"dependencies": { | ||
"crypto": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.21", | ||
"nock": "^13.2.4", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.3.5" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17513
149
1
5
10
+ Addedcrypto@^1.0.1
+ Addedcrypto@1.0.1(transitive)