From 6c7a890abee5ed3f3e97916cd299e5fc98e4e062 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 1 Oct 2019 19:07:59 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 14 +++++++++++++- ts/smartjwt.classes.smartjwt.ts | 10 +++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/test/test.ts b/test/test.ts index fb45e34..17032c6 100644 --- a/test/test.ts +++ b/test/test.ts @@ -2,6 +2,7 @@ import { expect, tap } from '@pushrocks/tapbundle'; import * as smartjwt from '../ts/index'; let smartjwtInstance: smartjwt.SmartJwt; +let testJwt: string; tap.test('should create a valid instance', async () => { smartjwtInstance = new smartjwt.SmartJwt(); @@ -10,7 +11,18 @@ tap.test('should create a valid instance', async () => { }); tap.test('should create a valid jwt', async () => { - + await smartjwtInstance.createNewKeyPair(); }); +tap.test('should create a new jwt', async () => { + testJwt = await smartjwtInstance.createJWT({hi: 'there'}); + console.log(testJwt); +}); + +tap.test('should verify a jwt', async () => { + const data = await smartjwtInstance.verifyJWTAndGetData(testJwt); + console.log(data); +}); + + tap.start(); diff --git a/ts/smartjwt.classes.smartjwt.ts b/ts/smartjwt.classes.smartjwt.ts index d6a1847..c238b5c 100644 --- a/ts/smartjwt.classes.smartjwt.ts +++ b/ts/smartjwt.classes.smartjwt.ts @@ -14,15 +14,19 @@ export class SmartJwt { * creates a JWT */ public async createJWT(payloadArg: any) { - return plugins.jsonwebtoken.sign(payloadArg, this.privateKey.toPemString()); + return plugins.jsonwebtoken.sign(payloadArg, this.privateKey.toPemString(), { + algorithm: 'RS256' + }); } /** * checks a JWT */ public async verifyJWTAndGetData(jwtArg: string) { - return plugins.jsonwebtoken.verify(jwtArg, this.publicKey.toPemString()); - }; + return plugins.jsonwebtoken.verify(jwtArg, this.publicKey.toPemString(), { + algorithms: ['RS256'] + }); + } /** * sets a private key to create jwts with