Tidy up generateKey
This commit is contained in:
parent
dbe3a11a27
commit
002e515ecf
|
@ -1,5 +1,6 @@
|
|||
var loopback = require('../loopback');
|
||||
var assert = require('assert');
|
||||
var generateKey = require('./utils').generateKey;
|
||||
|
||||
// Authentication schemes
|
||||
var AuthenticationSchemeSchema = {
|
||||
|
@ -94,18 +95,6 @@ var ApplicationSchema = {
|
|||
* Application management functions
|
||||
*/
|
||||
|
||||
var crypto = require('crypto');
|
||||
|
||||
function generateKey(hmacKey, algorithm, encoding) {
|
||||
hmacKey = hmacKey || 'loopback';
|
||||
algorithm = algorithm || 'sha1';
|
||||
encoding = encoding || 'hex';
|
||||
var hmac = crypto.createHmac(algorithm, hmacKey);
|
||||
var buf = crypto.randomBytes(32);
|
||||
hmac.update(buf);
|
||||
var key = hmac.digest(encoding);
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage client applications and organize their users.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Internal utilities for models
|
||||
*/
|
||||
var crypto = require('crypto');
|
||||
var assert = require('assert');
|
||||
|
||||
/**
|
||||
* Get the model class
|
||||
|
@ -24,7 +25,7 @@ function getModel(cls, base) {
|
|||
* @returns {String} The generated key
|
||||
*/
|
||||
function generateKey(hmacKey, algorithm, encoding) {
|
||||
hmacKey = hmacKey || 'loopback';
|
||||
assert(hmacKey, 'HMAC key is required');
|
||||
algorithm = algorithm || 'sha1';
|
||||
encoding = encoding || 'hex';
|
||||
var hmac = crypto.createHmac(algorithm, hmacKey);
|
||||
|
|
Loading…
Reference in New Issue