Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
d34feacdf1 | |||
6c7a890abe |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartjwt",
|
"name": "@pushrocks/smartjwt",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartjwt",
|
"name": "@pushrocks/smartjwt",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a package for handling jwt",
|
"description": "a package for handling jwt",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
14
test/test.ts
14
test/test.ts
@ -2,6 +2,7 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
import * as smartjwt from '../ts/index';
|
import * as smartjwt from '../ts/index';
|
||||||
|
|
||||||
let smartjwtInstance: smartjwt.SmartJwt;
|
let smartjwtInstance: smartjwt.SmartJwt;
|
||||||
|
let testJwt: string;
|
||||||
|
|
||||||
tap.test('should create a valid instance', async () => {
|
tap.test('should create a valid instance', async () => {
|
||||||
smartjwtInstance = new smartjwt.SmartJwt();
|
smartjwtInstance = new smartjwt.SmartJwt();
|
||||||
@ -10,7 +11,18 @@ tap.test('should create a valid instance', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a valid jwt', 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();
|
tap.start();
|
||||||
|
@ -14,15 +14,19 @@ export class SmartJwt {
|
|||||||
* creates a JWT
|
* creates a JWT
|
||||||
*/
|
*/
|
||||||
public async createJWT(payloadArg: any) {
|
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
|
* checks a JWT
|
||||||
*/
|
*/
|
||||||
public async verifyJWTAndGetData(jwtArg: string) {
|
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
|
* sets a private key to create jwts with
|
||||||
|
Reference in New Issue
Block a user