@payello-module/jwt 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
package/dist/JWT.js CHANGED
@@ -67,7 +67,9 @@ export class JWT {
67
67
  // Returns an object containing the extracted components of the JWT.
68
68
  return {
69
69
  header: header,
70
+ headerRaw: bits[0],
70
71
  payload: payload,
72
+ payloadRaw: bits[1],
71
73
  signature: bits[2]
72
74
  };
73
75
  }
@@ -86,14 +88,14 @@ export class JWT {
86
88
  }
87
89
  let verify = false;
88
90
  // Preparation of the data to verify the signature.
89
- const data = `${btoa(JSON.stringify(extracted.header))}.${btoa(JSON.stringify(extracted.payload))}`;
91
+ const data = `${extracted.headerRaw}.${extracted.payloadRaw}`;
90
92
  // Verification of the signature based on the algorithm specified in the header.
91
93
  switch (extracted.header.alg) {
92
94
  case 'HS256':
93
- verify = await HmacSha256.verify(data, extracted.signature, secretKey);
95
+ verify = extracted.signature === btoa(await HmacSha256.encrypt(data, secretKey)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
94
96
  break;
95
97
  case 'HS512':
96
- verify = await HmacSha512.verify(data, extracted.signature, secretKey);
98
+ verify = extracted.signature === btoa(await HmacSha512.encrypt(data, secretKey)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
97
99
  break;
98
100
  default:
99
101
  throw new JwtError(`Unsupported algorithm`);
@@ -1,6 +1,8 @@
1
1
  import { JwtHeader } from "./JwtHeader";
2
2
  export interface JwtExtract {
3
3
  header: JwtHeader;
4
+ headerRaw: string;
4
5
  payload: any;
6
+ payloadRaw: string;
5
7
  signature: string;
6
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payello-module/jwt",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "author": "Payello <devsupport@payello.com> (https://payello.com/)",
5
5
  "displayName": "@payello-module/jwt",
6
6
  "description": "JSON Web Token Module",