@kravc/dos 1.10.0 → 1.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/dos",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
package/src/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
 
2
- export declare function getOrFail(object: Record<string, any>, path: string): any;
3
-
4
2
  export declare type SortOrder = 'asc' | 'desc';
5
3
  export declare type Context = Record<string, any>;
6
4
  export declare type QueryMap = Record<string, any>;
@@ -124,3 +122,15 @@ export declare class Document<T> {
124
122
  hasAttributeChanged(attributePath: string): boolean;
125
123
  toJSON(): Record<string, any>;
126
124
  }
125
+
126
+ export declare function getOrFail(
127
+ object: Record<string, any>,
128
+ path: string
129
+ ): any;
130
+
131
+ export declare function verifyToken(
132
+ context: Context,
133
+ token: string,
134
+ publicKey: string,
135
+ algorithm: string,
136
+ ): Promise<[ boolean, string | undefined ]>;
package/src/index.js CHANGED
@@ -15,6 +15,7 @@ module.exports = {
15
15
  handler: require('./helpers/handler'),
16
16
  security: require('./security'),
17
17
  getOrFail: require('./helpers/getOrFail'),
18
+ verifyToken: require('./security/verifyToken'),
18
19
  JwtAuthorization: require('./security/JwtAuthorization'),
19
20
  SystemAuthorization: require('./security/SystemAuthorization')
20
21
  }
@@ -53,8 +53,9 @@ class JwtAuthorization {
53
53
  publicKey,
54
54
  cookieName,
55
55
  algorithm = 'RS256',
56
- tokenVerificationMethod = verifyToken,
57
- accessVerificationMethod = () => [ true ]
56
+ normalizePayload = payload => payload,
57
+ tokenVerificationMethod = verifyToken,
58
+ accessVerificationMethod = () => [ true ],
58
59
  }) {
59
60
  this._name = name
60
61
  this._publicKey = publicKey
@@ -63,6 +64,7 @@ class JwtAuthorization {
63
64
 
64
65
  this._verifyToken = tokenVerificationMethod
65
66
  this._verifyAccess = accessVerificationMethod
67
+ this._normalizePayload = normalizePayload
66
68
  }
67
69
 
68
70
  async verify(context) {
@@ -111,7 +113,9 @@ class JwtAuthorization {
111
113
  return { isAuthorized: false, error }
112
114
  }
113
115
 
114
- return { isAuthorized: true, ...payload }
116
+ const normalizedPayload = this._normalizePayload(payload)
117
+
118
+ return { isAuthorized: true, ...normalizedPayload }
115
119
  }
116
120
  }
117
121