1
0
Fork 0

Fix encoding issue

refactor/models
Matthew 2019-11-16 20:48:40 -05:00
parent 020d530451
commit b9101de1cc
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 2 additions and 2 deletions

View File

@ -19,13 +19,13 @@ export default class Security {
public async createBearer(_id: string): Promise<string> { public async createBearer(_id: string): Promise<string> {
const account = await this.client.db.Account.findOne({ _id }); const account = await this.client.db.Account.findOne({ _id });
if (!account) throw new Error(`Account [${_id}] cannot be found.`); if (!account) throw new Error(`Account [${_id}] cannot be found.`);
const bearer = crypto.randomBytes(12); const bearer = crypto.randomBytes(12).toString('base64');
const sign = crypto.createSign('sha3-224'); const sign = crypto.createSign('sha3-224');
sign.update(bearer); sign.update(bearer);
sign.end(); sign.end();
const signature = sign.sign(this.keyPair.privateKey, 'hex'); const signature = sign.sign(this.keyPair.privateKey, 'hex');
await account.updateOne({ bearerSignature: signature }); await account.updateOne({ bearerSignature: signature });
return bearer.toString('base64'); return bearer;
} }
public async checkBearer(_id: string, bearer: string): Promise<boolean> { public async checkBearer(_id: string, bearer: string): Promise<boolean> {