'use strict';
const { common } = require('@squeep/api-dingus');
-const b64u = require('@squeep/base64url');
const { randomBytes } = require('crypto');
const { promisify } = require('util');
const randomBytesAsync = promisify(randomBytes);
module.exports = Object.assign(Object.create(common), {
randomBytesAsync,
- ...b64u,
-});
\ No newline at end of file
+});
*/
async getSalt() {
const saltBytes = await common.randomBytesAsync(this.saltBytes);
- return common.base64ToBase64URL(saltBytes.toString('base64'));
+ return saltBytes.toString('base64url');
}
* @param {String} identifier UUID
*/
async authenticate(identifier, secret) {
+ const authenticationType = 'Bearer';
const currentEpoch = ResourceAuthenticator.currentEpoch.toString();
const smallIdentifier = ResourceAuthenticator.ensmallenIdentifier(identifier);
const salt = await this.getSalt();
salt,
this.createDigest(secret, smallIdentifier, currentEpoch, salt),
];
- return parts.join(':');
+ const token = parts.join(':');
+ return [authenticationType, token].join(' ');
}
* @returns {String} b64u-encoded UUID
*/
static ensmallenIdentifier(identifier) {
- const uuidBase64 = Buffer.from(uuid.parse(identifier)).toString('base64');
- return common.base64ToBase64URL(uuidBase64);
+ return Buffer.from(uuid.parse(identifier)).toString('base64url');
}
* @returns {String} UUID
*/
static embiggenIdentifier(small) {
- const uuidBase64 = common.base64URLToBase64(small);
- const uuidBuffer = Buffer.from(uuidBase64, 'base64');
+ const uuidBuffer = Buffer.from(small, 'base64url');
return uuid.stringify(uuidBuffer);
}
createDigest(secret, ...contents) {
const hmac = crypto.createHmac(this.digestAlgorithm, secret);
contents.forEach((content) => hmac.update(Buffer.from(content)));
- const digestBase64 = hmac.digest('base64');
- return common.base64ToBase64URL(digestBase64);
+ return hmac.digest('base64url');
}
const secret = 'secrety';
sinon.stub(ResourceAuthenticator, 'currentEpoch').get(() => 1648836029);
sinon.stub(ra, 'getSalt').resolves('xxxxx');
- const expected = 'bq7ZSLHkEeyakQAlkF9xSg:1648836029:xxxxx:fdUYC8Gqe0nAyX_-SWvRsPsx0UjY-vV-Ff0A52j6Zfw';
+ const expected = 'Bearer bq7ZSLHkEeyakQAlkF9xSg:1648836029:xxxxx:fdUYC8Gqe0nAyX_-SWvRsPsx0UjY-vV-Ff0A52j6Zfw';
const result = await ra.authenticate(identifier, secret);
assert.strictEqual(result, expected);
});
});
});
-}); // ResourceAuthenticator
\ No newline at end of file
+}); // ResourceAuthenticator