vona-module-a-jwt 5.0.10 → 5.0.12

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/dist/index.js CHANGED
@@ -1,3 +1,273 @@
1
- export * from "./.metadata/index.js";
2
- export * from "./lib/index.js";
3
- export * from "./types/index.js";
1
+ import { BeanInfo, BeanBase, deepExtend, cast, BeanScopeBase } from 'vona';
2
+ import { Bean, Scope } from 'vona-module-a-bean';
3
+ import ms from 'ms';
4
+ import jwt from 'jsonwebtoken';
5
+ import { Service, Dto } from 'vona-module-a-web';
6
+ import { Api } from 'vona-module-a-openapi';
7
+
8
+ var _dec$4, _dec2$4, _class$4;
9
+ let ServiceJwtClient = (_dec$4 = Service(), _dec2$4 = BeanInfo({
10
+ module: "a-jwt"
11
+ }), _dec$4(_class$4 = _dec2$4(_class$4 = class ServiceJwtClient extends BeanBase {
12
+ constructor(...args) {
13
+ super(...args);
14
+ this._jwtInstance = void 0;
15
+ this._clientName = void 0;
16
+ this._clientOptions = void 0;
17
+ }
18
+ get instance() {
19
+ return this._jwtInstance;
20
+ }
21
+ __init__(clientName) {
22
+ this._createClient(clientName);
23
+ }
24
+ _createClient(clientName) {
25
+ clientName = clientName || 'access';
26
+ const configJwt = this.scope.config;
27
+ const configClient = configJwt.clients[clientName];
28
+ if (!configClient) throw new Error(`jwt client not found: ${clientName}`);
29
+ const secret = configJwt.default.secret ?? this.app.config.server.keys[0];
30
+ this._clientOptions = deepExtend({}, configJwt.default, {
31
+ secret
32
+ }, configClient);
33
+ this._clientName = clientName;
34
+ this._jwtInstance = jwt;
35
+ }
36
+ get fieldClient() {
37
+ return this.scope.config.field.payload.client;
38
+ }
39
+ get fieldPath() {
40
+ return this.scope.config.field.payload.path;
41
+ }
42
+ get fieldData() {
43
+ return this.scope.config.field.payload.data;
44
+ }
45
+ async sign(payloadData, options) {
46
+ return new Promise((resolve, reject) => {
47
+ const payload = {
48
+ [this.fieldClient]: this._clientName,
49
+ [this.fieldData]: payloadData
50
+ };
51
+ if (options?.path) payload[this.fieldPath] = options.path;
52
+ let signOptions = this._clientOptions.signOptions;
53
+ if (options?.dev) {
54
+ signOptions = Object.assign({}, signOptions, {
55
+ expiresIn: this.scope.config.clients.refresh.signOptions.expiresIn
56
+ });
57
+ }
58
+ if (options?.temp) {
59
+ signOptions = Object.assign({}, signOptions, {
60
+ expiresIn: this.scope.config.tempToken.signOptions.expiresIn
61
+ });
62
+ }
63
+ this._jwtInstance.sign(payload, this._clientOptions.secret, signOptions, (err, encoded) => {
64
+ if (err) return reject(err);
65
+ resolve(encoded);
66
+ });
67
+ });
68
+ }
69
+ async verify(token) {
70
+ if (!token && this._clientName === 'access') token = this.scope.service.jwtExtract.fromAllWays();
71
+ if (!token) return undefined;
72
+ return new Promise((resolve, reject) => {
73
+ this._jwtInstance.verify(token, this._clientOptions.secret, this._clientOptions.signOptions, (err, decoded) => {
74
+ if (err) return reject(err);
75
+ const payload = cast(decoded);
76
+ // check field client
77
+ if (payload[this.fieldClient] !== this._clientName) return this.app.throw(401);
78
+ // check field path
79
+ if (payload[this.fieldPath] && payload[this.fieldPath] !== this.ctx.route.routePathRaw) return this.app.throw(401);
80
+ // passed
81
+ resolve(payload[this.fieldData]);
82
+ });
83
+ });
84
+ }
85
+ }) || _class$4) || _class$4);
86
+
87
+ var _dec$3, _dec2$3, _class$3;
88
+ let BeanJwt = (_dec$3 = Bean(), _dec2$3 = BeanInfo({
89
+ module: "a-jwt"
90
+ }), _dec$3(_class$3 = _dec2$3(_class$3 = class BeanJwt extends BeanBase {
91
+ get(clientName) {
92
+ return this.app.bean._getBeanSelector(ServiceJwtClient, clientName);
93
+ }
94
+ async create(payloadData, options) {
95
+ // accessToken
96
+ const accessToken = await this.get('access').sign(payloadData, options);
97
+ // refreshToken
98
+ const refreshToken = await this.get('refresh').sign(payloadData, options);
99
+ // expiresIn
100
+ let expiresIn = this.scope.config.clients.access.signOptions.expiresIn;
101
+ if (typeof expiresIn === 'string') expiresIn = ms(expiresIn);
102
+ // ok
103
+ return {
104
+ accessToken,
105
+ refreshToken,
106
+ expiresIn
107
+ };
108
+ }
109
+ async createTemp(payloadData, options) {
110
+ return await this.get('access').sign(payloadData, Object.assign({}, options, {
111
+ temp: true
112
+ }));
113
+ }
114
+ async createOauth(payloadData, options) {
115
+ return await this.get('oauth').sign(payloadData, options);
116
+ }
117
+ async createOauthState(payloadData, options) {
118
+ return await this.get('oauthstate').sign(payloadData, options);
119
+ }
120
+ async createOauthCode(payloadData, options) {
121
+ return await this.get('code').sign(payloadData, options);
122
+ }
123
+ }) || _class$3) || _class$3);
124
+
125
+ function config(app) {
126
+ return {
127
+ field: {
128
+ payload: {
129
+ client: 'client',
130
+ path: 'path',
131
+ data: 'data'
132
+ },
133
+ extract: {
134
+ header: '',
135
+ headerAuth: 'authorization',
136
+ headerAuthScheme: 'bearer',
137
+ query: 'auth_token',
138
+ cookie: 'token'
139
+ }
140
+ },
141
+ tempToken: {
142
+ signOptions: {
143
+ expiresIn: 10 * 60
144
+ }
145
+ },
146
+ default: {
147
+ secret: undefined,
148
+ signOptions: {
149
+ issuer: app.meta.env.APP_NAME
150
+ }
151
+ },
152
+ clients: {
153
+ access: {
154
+ signOptions: {
155
+ expiresIn: 2 * 60 * 60
156
+ }
157
+ },
158
+ refresh: {
159
+ signOptions: {
160
+ expiresIn: 7 * 24 * 60 * 60
161
+ }
162
+ },
163
+ oauth: {
164
+ signOptions: {
165
+ expiresIn: 5 * 60
166
+ }
167
+ },
168
+ oauthstate: {
169
+ signOptions: {
170
+ expiresIn: 5 * 60
171
+ }
172
+ },
173
+ code: {
174
+ signOptions: {
175
+ expiresIn: 3 * 60
176
+ }
177
+ }
178
+ }
179
+ };
180
+ }
181
+
182
+ function _applyDecoratedDescriptor(i, e, r, n, l) {
183
+ var a = {};
184
+ return Object.keys(n).forEach(function (i) {
185
+ a[i] = n[i];
186
+ }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = true), a = r.slice().reverse().reduce(function (r, n) {
187
+ return n(i, e, r) || r;
188
+ }, a), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
189
+ }
190
+ function _initializerDefineProperty(e, i, r, l) {
191
+ r && Object.defineProperty(e, i, {
192
+ enumerable: r.enumerable,
193
+ configurable: r.configurable,
194
+ writable: r.writable,
195
+ value: r.initializer ? r.initializer.call(l) : void 0
196
+ });
197
+ }
198
+
199
+ var _dec$2, _dec2$2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class$2, _class2, _descriptor, _descriptor2, _descriptor3;
200
+ let DtoJwtToken = (_dec$2 = Dto(), _dec2$2 = BeanInfo({
201
+ module: "a-jwt"
202
+ }), _dec3 = Api.field(), _dec4 = Reflect.metadata("design:type", String), _dec5 = Api.field(), _dec6 = Reflect.metadata("design:type", String), _dec7 = Api.field(), _dec8 = Reflect.metadata("design:type", Number), _dec$2(_class$2 = _dec2$2(_class$2 = (_class2 = class DtoJwtToken {
203
+ constructor() {
204
+ _initializerDefineProperty(this, "accessToken", _descriptor, this);
205
+ _initializerDefineProperty(this, "refreshToken", _descriptor2, this);
206
+ _initializerDefineProperty(this, "expiresIn", _descriptor3, this);
207
+ }
208
+ }, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "accessToken", [_dec3, _dec4], {
209
+ configurable: true,
210
+ enumerable: true,
211
+ writable: true,
212
+ initializer: null
213
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "refreshToken", [_dec5, _dec6], {
214
+ configurable: true,
215
+ enumerable: true,
216
+ writable: true,
217
+ initializer: null
218
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "expiresIn", [_dec7, _dec8], {
219
+ configurable: true,
220
+ enumerable: true,
221
+ writable: true,
222
+ initializer: null
223
+ }), _class2)) || _class$2) || _class$2);
224
+
225
+ const re = /(\S+)\s+(\S+)/;
226
+ function parseAuthHeader(headerValue) {
227
+ if (typeof headerValue !== 'string') return;
228
+ const matches = headerValue.match(re);
229
+ return matches && {
230
+ scheme: matches[1],
231
+ value: matches[2]
232
+ };
233
+ }
234
+
235
+ var _dec$1, _dec2$1, _class$1;
236
+ let ServiceJwtExtract = (_dec$1 = Service(), _dec2$1 = BeanInfo({
237
+ module: "a-jwt"
238
+ }), _dec$1(_class$1 = _dec2$1(_class$1 = class ServiceJwtExtract extends BeanBase {
239
+ fromHeader() {
240
+ if (!this.scope.config.field.extract.header) return;
241
+ return this.ctx.request.headers[this.scope.config.field.extract.header];
242
+ }
243
+ fromQuery() {
244
+ return this.ctx.request.query[this.scope.config.field.extract.query];
245
+ }
246
+ fromAuthHeaderWithScheme() {
247
+ const headerValue = this.ctx.request.headers[this.scope.config.field.extract.headerAuth];
248
+ const auth = parseAuthHeader(headerValue);
249
+ if (!auth || auth.scheme.toLocaleLowerCase() !== this.scope.config.field.extract.headerAuthScheme.toLocaleLowerCase()) return;
250
+ return auth.value;
251
+ }
252
+ fromCookie() {
253
+ return this.ctx.cookies.get(this.scope.config.field.extract.cookie);
254
+ }
255
+ fromAllWays() {
256
+ let token = this.fromQuery();
257
+ if (!token) token = this.fromAuthHeaderWithScheme();
258
+ if (!token) token = this.fromHeader();
259
+ if (!token) token = this.fromCookie();
260
+ return token;
261
+ }
262
+ }) || _class$1) || _class$1);
263
+
264
+ var _dec, _dec2, _class;
265
+ let ScopeModuleAJwt = (_dec = Scope(), _dec2 = BeanInfo({
266
+ module: "a-jwt"
267
+ }), _dec(_class = _dec2(_class = class ScopeModuleAJwt extends BeanScopeBase {}) || _class) || _class);
268
+
269
+ /** scope: end */
270
+
271
+ const ErrorMessageJwtExpired = 'jwt expired';
272
+
273
+ export { BeanJwt, DtoJwtToken, ErrorMessageJwtExpired, ScopeModuleAJwt, ServiceJwtClient, ServiceJwtExtract, config, parseAuthHeader };
@@ -1,4 +1,5 @@
1
1
  import type { SignOptions } from 'jsonwebtoken';
2
+ export declare const ErrorMessageJwtExpired = "jwt expired";
2
3
  export interface IJwtToken {
3
4
  accessToken: string;
4
5
  refreshToken: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-jwt",
3
3
  "type": "module",
4
- "version": "5.0.10",
4
+ "version": "5.0.12",
5
5
  "title": "a-jwt",
6
6
  "vonaModule": {
7
7
  "dependencies": {}
@@ -36,6 +36,6 @@
36
36
  },
37
37
  "scripts": {
38
38
  "clean": "rimraf dist tsconfig.build.tsbuildinfo",
39
- "tsc:publish": "npm run clean && tsc -p tsconfig.build.json"
39
+ "tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
40
40
  }
41
41
  }
@@ -1,37 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- /** config: end */
8
- /** scope: begin */
9
- import { BeanScopeBase } from 'vona';
10
- import { Scope } from 'vona-module-a-bean';
11
- import 'vona';
12
- /** service: end */
13
- /** service: begin */
14
- import 'vona';
15
- import 'vona';
16
- import 'vona';
17
- import 'vona';
18
- import 'vona';
19
- /** bean: begin */
20
- export * from "../bean/bean.jwt.js";
21
- /** service: end */
22
- /** config: begin */
23
- export * from "../config/config.js";
24
- /** bean: end */
25
- /** dto: begin */
26
- export * from "../dto/jwtToken.js";
27
- /** dto: end */
28
- /** service: begin */
29
- export * from "../service/jwtClient.js";
30
- export * from "../service/jwtExtract.js";
31
- let ScopeModuleAJwt = class ScopeModuleAJwt extends BeanScopeBase {
32
- };
33
- ScopeModuleAJwt = __decorate([
34
- Scope()
35
- ], ScopeModuleAJwt);
36
- export { ScopeModuleAJwt };
37
- /** scope: end */
@@ -1,2 +0,0 @@
1
- export const __ThisModule__ = 'a-jwt';
2
- export { ScopeModuleAJwt as ScopeModule } from "./index.js";
@@ -1,47 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import ms from 'ms';
8
- import { BeanBase } from 'vona';
9
- import { Bean } from 'vona-module-a-bean';
10
- import { ServiceJwtClient } from "../service/jwtClient.js";
11
- let BeanJwt = class BeanJwt extends BeanBase {
12
- get(clientName) {
13
- return this.app.bean._getBeanSelector(ServiceJwtClient, clientName);
14
- }
15
- async create(payloadData, options) {
16
- // accessToken
17
- const accessToken = await this.get('access').sign(payloadData, options);
18
- // refreshToken
19
- const refreshToken = await this.get('refresh').sign(payloadData, options);
20
- // expiresIn
21
- let expiresIn = this.scope.config.clients.access.signOptions.expiresIn;
22
- if (typeof expiresIn === 'string')
23
- expiresIn = ms(expiresIn);
24
- // ok
25
- return {
26
- accessToken,
27
- refreshToken,
28
- expiresIn,
29
- };
30
- }
31
- async createTemp(payloadData, options) {
32
- return await this.get('access').sign(payloadData, Object.assign({}, options, { temp: true }));
33
- }
34
- async createOauth(payloadData, options) {
35
- return await this.get('oauth').sign(payloadData, options);
36
- }
37
- async createOauthState(payloadData, options) {
38
- return await this.get('oauthstate').sign(payloadData, options);
39
- }
40
- async createOauthCode(payloadData, options) {
41
- return await this.get('code').sign(payloadData, options);
42
- }
43
- };
44
- BeanJwt = __decorate([
45
- Bean()
46
- ], BeanJwt);
47
- export { BeanJwt };
@@ -1,42 +0,0 @@
1
- export function config(app) {
2
- return {
3
- field: {
4
- payload: {
5
- client: 'client',
6
- path: 'path',
7
- data: 'data',
8
- },
9
- extract: {
10
- header: '',
11
- headerAuth: 'authorization',
12
- headerAuthScheme: 'bearer',
13
- query: 'auth_token',
14
- cookie: 'token',
15
- },
16
- },
17
- tempToken: {
18
- signOptions: { expiresIn: 10 * 60 },
19
- },
20
- default: {
21
- secret: undefined,
22
- signOptions: { issuer: app.meta.env.APP_NAME },
23
- },
24
- clients: {
25
- access: {
26
- signOptions: { expiresIn: 2 * 60 * 60 },
27
- },
28
- refresh: {
29
- signOptions: { expiresIn: 7 * 24 * 60 * 60 },
30
- },
31
- oauth: {
32
- signOptions: { expiresIn: 5 * 60 },
33
- },
34
- oauthstate: {
35
- signOptions: { expiresIn: 5 * 60 },
36
- },
37
- code: {
38
- signOptions: { expiresIn: 3 * 60 },
39
- },
40
- },
41
- };
42
- }
@@ -1,32 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { Api } from 'vona-module-a-openapi';
11
- import { Dto } from 'vona-module-a-web';
12
- let DtoJwtToken = class DtoJwtToken {
13
- accessToken;
14
- refreshToken;
15
- expiresIn;
16
- };
17
- __decorate([
18
- Api.field(),
19
- __metadata("design:type", String)
20
- ], DtoJwtToken.prototype, "accessToken", void 0);
21
- __decorate([
22
- Api.field(),
23
- __metadata("design:type", String)
24
- ], DtoJwtToken.prototype, "refreshToken", void 0);
25
- __decorate([
26
- Api.field(),
27
- __metadata("design:type", Number)
28
- ], DtoJwtToken.prototype, "expiresIn", void 0);
29
- DtoJwtToken = __decorate([
30
- Dto()
31
- ], DtoJwtToken);
32
- export { DtoJwtToken };
@@ -1,7 +0,0 @@
1
- const re = /(\S+)\s+(\S+)/;
2
- export function parseAuthHeader(headerValue) {
3
- if (typeof headerValue !== 'string')
4
- return;
5
- const matches = headerValue.match(re);
6
- return matches && { scheme: matches[1], value: matches[2] };
7
- }
package/dist/lib/index.js DELETED
@@ -1 +0,0 @@
1
- export * from "./authHeader.js";
@@ -1,87 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import jwt from 'jsonwebtoken';
8
- import { BeanBase, cast, deepExtend } from 'vona';
9
- import { Service } from 'vona-module-a-web';
10
- let ServiceJwtClient = class ServiceJwtClient extends BeanBase {
11
- _jwtInstance;
12
- _clientName;
13
- _clientOptions;
14
- get instance() {
15
- return this._jwtInstance;
16
- }
17
- __init__(clientName) {
18
- this._createClient(clientName);
19
- }
20
- _createClient(clientName) {
21
- clientName = clientName || 'access';
22
- const configJwt = this.scope.config;
23
- const configClient = configJwt.clients[clientName];
24
- if (!configClient)
25
- throw new Error(`jwt client not found: ${clientName}`);
26
- const secret = configJwt.default.secret ?? this.app.config.server.keys[0];
27
- this._clientOptions = deepExtend({}, configJwt.default, { secret }, configClient);
28
- this._clientName = clientName;
29
- this._jwtInstance = jwt;
30
- }
31
- get fieldClient() {
32
- return this.scope.config.field.payload.client;
33
- }
34
- get fieldPath() {
35
- return this.scope.config.field.payload.path;
36
- }
37
- get fieldData() {
38
- return this.scope.config.field.payload.data;
39
- }
40
- async sign(payloadData, options) {
41
- return new Promise((resolve, reject) => {
42
- const payload = {
43
- [this.fieldClient]: this._clientName,
44
- [this.fieldData]: payloadData,
45
- };
46
- if (options?.path)
47
- payload[this.fieldPath] = options.path;
48
- let signOptions = this._clientOptions.signOptions;
49
- if (options?.dev) {
50
- signOptions = Object.assign({}, signOptions, { expiresIn: this.scope.config.clients.refresh.signOptions.expiresIn });
51
- }
52
- if (options?.temp) {
53
- signOptions = Object.assign({}, signOptions, { expiresIn: this.scope.config.tempToken.signOptions.expiresIn });
54
- }
55
- this._jwtInstance.sign(payload, this._clientOptions.secret, signOptions, (err, encoded) => {
56
- if (err)
57
- return reject(err);
58
- resolve(encoded);
59
- });
60
- });
61
- }
62
- async verify(token) {
63
- if (!token && this._clientName === 'access')
64
- token = this.scope.service.jwtExtract.fromAllWays();
65
- if (!token)
66
- return undefined;
67
- return new Promise((resolve, reject) => {
68
- this._jwtInstance.verify(token, this._clientOptions.secret, this._clientOptions.signOptions, (err, decoded) => {
69
- if (err)
70
- return reject(err);
71
- const payload = cast(decoded);
72
- // check field client
73
- if (payload[this.fieldClient] !== this._clientName)
74
- return this.app.throw(401);
75
- // check field path
76
- if (payload[this.fieldPath] && payload[this.fieldPath] !== this.ctx.route.routePathRaw)
77
- return this.app.throw(401);
78
- // passed
79
- resolve(payload[this.fieldData]);
80
- });
81
- });
82
- }
83
- };
84
- ServiceJwtClient = __decorate([
85
- Service()
86
- ], ServiceJwtClient);
87
- export { ServiceJwtClient };
@@ -1,43 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { BeanBase } from 'vona';
8
- import { Service } from 'vona-module-a-web';
9
- import { parseAuthHeader } from "../lib/authHeader.js";
10
- let ServiceJwtExtract = class ServiceJwtExtract extends BeanBase {
11
- fromHeader() {
12
- if (!this.scope.config.field.extract.header)
13
- return;
14
- return this.ctx.request.headers[this.scope.config.field.extract.header];
15
- }
16
- fromQuery() {
17
- return this.ctx.request.query[this.scope.config.field.extract.query];
18
- }
19
- fromAuthHeaderWithScheme() {
20
- const headerValue = this.ctx.request.headers[this.scope.config.field.extract.headerAuth];
21
- const auth = parseAuthHeader(headerValue);
22
- if (!auth || auth.scheme.toLocaleLowerCase() !== this.scope.config.field.extract.headerAuthScheme.toLocaleLowerCase())
23
- return;
24
- return auth.value;
25
- }
26
- fromCookie() {
27
- return this.ctx.cookies.get(this.scope.config.field.extract.cookie);
28
- }
29
- fromAllWays() {
30
- let token = this.fromQuery();
31
- if (!token)
32
- token = this.fromAuthHeaderWithScheme();
33
- if (!token)
34
- token = this.fromHeader();
35
- if (!token)
36
- token = this.fromCookie();
37
- return token;
38
- }
39
- };
40
- ServiceJwtExtract = __decorate([
41
- Service()
42
- ], ServiceJwtExtract);
43
- export { ServiceJwtExtract };
@@ -1 +0,0 @@
1
- export * from "./jwt.js";
package/dist/types/jwt.js DELETED
@@ -1 +0,0 @@
1
- export {};