*/
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');
}