vona-module-a-jwt 5.0.8 → 5.0.10
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/.metadata/index.d.ts +101 -0
- package/dist/.metadata/index.js +37 -0
- package/dist/.metadata/this.d.ts +2 -0
- package/dist/.metadata/this.js +2 -0
- package/dist/bean/bean.jwt.d.ts +11 -0
- package/dist/bean/bean.jwt.js +47 -0
- package/dist/config/config.d.ts +3 -0
- package/dist/config/config.js +42 -0
- package/dist/dto/jwtToken.d.ts +9 -0
- package/dist/dto/jwtToken.js +32 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/lib/authHeader.d.ts +4 -0
- package/dist/lib/authHeader.js +7 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/service/jwtClient.d.ts +16 -0
- package/dist/service/jwtClient.js +87 -0
- package/dist/service/jwtExtract.d.ts +8 -0
- package/dist/service/jwtExtract.js +43 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/jwt.d.ts +49 -0
- package/dist/types/jwt.js +1 -0
- package/package.json +7 -3
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { BeanScopeUtil, TypeModuleConfig } from 'vona';
|
|
2
|
+
import type { TypeEntityOptionsFields } from 'vona-module-a-openapi';
|
|
3
|
+
/** bean: end */
|
|
4
|
+
/** bean: begin */
|
|
5
|
+
import type { BeanJwt } from '../bean/bean.jwt.ts';
|
|
6
|
+
import type { config } from '../config/config.ts';
|
|
7
|
+
import type { IDtoOptionsJwtToken } from '../dto/jwtToken.ts';
|
|
8
|
+
/** dto: end */
|
|
9
|
+
/** dto: begin */
|
|
10
|
+
import type { DtoJwtToken } from '../dto/jwtToken.ts';
|
|
11
|
+
/** service: end */
|
|
12
|
+
/** service: begin */
|
|
13
|
+
import type { ServiceJwtClient } from '../service/jwtClient.ts';
|
|
14
|
+
import type { ServiceJwtExtract } from '../service/jwtExtract.ts';
|
|
15
|
+
/** config: end */
|
|
16
|
+
/** scope: begin */
|
|
17
|
+
import { BeanScopeBase } from 'vona';
|
|
18
|
+
import 'vona';
|
|
19
|
+
/** service: end */
|
|
20
|
+
/** service: begin */
|
|
21
|
+
import 'vona';
|
|
22
|
+
import 'vona';
|
|
23
|
+
import 'vona';
|
|
24
|
+
import 'vona';
|
|
25
|
+
import 'vona';
|
|
26
|
+
/** bean: begin */
|
|
27
|
+
export * from '../bean/bean.jwt.ts';
|
|
28
|
+
declare module 'vona' {
|
|
29
|
+
}
|
|
30
|
+
declare module 'vona-module-a-jwt' {
|
|
31
|
+
interface BeanJwt {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
declare module 'vona' {
|
|
35
|
+
interface IBeanRecordGlobal {
|
|
36
|
+
jwt: BeanJwt;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** service: end */
|
|
40
|
+
/** config: begin */
|
|
41
|
+
export * from '../config/config.ts';
|
|
42
|
+
declare module 'vona-module-a-web' {
|
|
43
|
+
interface IDtoRecord {
|
|
44
|
+
'a-jwt:jwtToken': IDtoOptionsJwtToken;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
declare module 'vona-module-a-jwt' {
|
|
48
|
+
}
|
|
49
|
+
declare module 'vona-module-a-jwt' {
|
|
50
|
+
interface IDtoOptionsJwtToken {
|
|
51
|
+
fields?: TypeEntityOptionsFields<DtoJwtToken, IDtoOptionsJwtToken['fieldsMore']>;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** bean: end */
|
|
55
|
+
/** dto: begin */
|
|
56
|
+
export * from '../dto/jwtToken.ts';
|
|
57
|
+
/** dto: end */
|
|
58
|
+
/** service: begin */
|
|
59
|
+
export * from '../service/jwtClient.ts';
|
|
60
|
+
declare module 'vona-module-a-web' {
|
|
61
|
+
interface IServiceRecord {
|
|
62
|
+
'a-jwt:jwtClient': never;
|
|
63
|
+
'a-jwt:jwtExtract': never;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
declare module 'vona-module-a-jwt' {
|
|
67
|
+
interface ServiceJwtClient {
|
|
68
|
+
}
|
|
69
|
+
interface ServiceJwtExtract {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export interface IModuleService {
|
|
73
|
+
jwtClient: ServiceJwtClient;
|
|
74
|
+
jwtExtract: ServiceJwtExtract;
|
|
75
|
+
}
|
|
76
|
+
declare module 'vona' {
|
|
77
|
+
interface IBeanRecordGeneral {
|
|
78
|
+
'a-jwt.service.jwtClient': ServiceJwtClient;
|
|
79
|
+
'a-jwt.service.jwtExtract': ServiceJwtExtract;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export * from '../service/jwtExtract.ts';
|
|
83
|
+
export declare class ScopeModuleAJwt extends BeanScopeBase {
|
|
84
|
+
}
|
|
85
|
+
export interface ScopeModuleAJwt {
|
|
86
|
+
util: BeanScopeUtil;
|
|
87
|
+
config: TypeModuleConfig<typeof config>;
|
|
88
|
+
service: IModuleService;
|
|
89
|
+
}
|
|
90
|
+
declare module 'vona' {
|
|
91
|
+
interface IBeanScopeRecord {
|
|
92
|
+
'a-jwt': ScopeModuleAJwt;
|
|
93
|
+
}
|
|
94
|
+
interface IBeanScopeContainer {
|
|
95
|
+
jwt: ScopeModuleAJwt;
|
|
96
|
+
}
|
|
97
|
+
interface IBeanScopeConfig {
|
|
98
|
+
'a-jwt': ReturnType<typeof config>;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** scope: end */
|
|
@@ -0,0 +1,37 @@
|
|
|
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 */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IJwtClientRecord, IJwtSignOptions, IJwtToken, IPayloadDataBase } from '../types/jwt.ts';
|
|
2
|
+
import { BeanBase } from 'vona';
|
|
3
|
+
import { ServiceJwtClient } from '../service/jwtClient.ts';
|
|
4
|
+
export declare class BeanJwt extends BeanBase {
|
|
5
|
+
get(clientName?: keyof IJwtClientRecord): ServiceJwtClient;
|
|
6
|
+
create(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<IJwtToken>;
|
|
7
|
+
createTemp(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
|
|
8
|
+
createOauth(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
|
|
9
|
+
createOauthState(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
|
|
10
|
+
createOauthCode(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 };
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import type { IJwtToken } from '../types/jwt.ts';
|
|
3
|
+
export interface IDtoOptionsJwtToken extends IDecoratorDtoOptions {
|
|
4
|
+
}
|
|
5
|
+
export declare class DtoJwtToken implements IJwtToken {
|
|
6
|
+
accessToken: string;
|
|
7
|
+
refreshToken: string;
|
|
8
|
+
expiresIn: number;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './authHeader.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./authHeader.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IJwtClientRecord, IJwtSignOptions, IPayloadDataBase } from '../types/jwt.ts';
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
3
|
+
import { BeanBase } from 'vona';
|
|
4
|
+
export declare class ServiceJwtClient extends BeanBase {
|
|
5
|
+
private _jwtInstance;
|
|
6
|
+
private _clientName;
|
|
7
|
+
private _clientOptions;
|
|
8
|
+
get instance(): typeof jwt;
|
|
9
|
+
protected __init__(clientName?: keyof IJwtClientRecord): void;
|
|
10
|
+
private _createClient;
|
|
11
|
+
private get fieldClient();
|
|
12
|
+
private get fieldPath();
|
|
13
|
+
private get fieldData();
|
|
14
|
+
sign(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
|
|
15
|
+
verify(token?: string): Promise<IPayloadDataBase | undefined>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BeanBase } from 'vona';
|
|
2
|
+
export declare class ServiceJwtExtract extends BeanBase {
|
|
3
|
+
fromHeader(): string | undefined;
|
|
4
|
+
fromQuery(): string;
|
|
5
|
+
fromAuthHeaderWithScheme(): string | undefined;
|
|
6
|
+
fromCookie(): string | undefined;
|
|
7
|
+
fromAllWays(): string | undefined;
|
|
8
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './jwt.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./jwt.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { SignOptions } from 'jsonwebtoken';
|
|
2
|
+
export interface IJwtToken {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
refreshToken: string;
|
|
5
|
+
expiresIn: number;
|
|
6
|
+
}
|
|
7
|
+
export interface IJwtClientRecord {
|
|
8
|
+
access: never;
|
|
9
|
+
refresh: never;
|
|
10
|
+
oauth: never;
|
|
11
|
+
oauthstate: never;
|
|
12
|
+
code: never;
|
|
13
|
+
}
|
|
14
|
+
export interface IJwtSignOptions {
|
|
15
|
+
path?: string | string[];
|
|
16
|
+
dev?: boolean;
|
|
17
|
+
temp?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface IJwtClientOptions {
|
|
20
|
+
secret?: string;
|
|
21
|
+
signOptions: SignOptions;
|
|
22
|
+
}
|
|
23
|
+
export interface ConfigJwt {
|
|
24
|
+
field: {
|
|
25
|
+
payload: {
|
|
26
|
+
client: string;
|
|
27
|
+
path: string;
|
|
28
|
+
data: string;
|
|
29
|
+
};
|
|
30
|
+
extract: {
|
|
31
|
+
header: string;
|
|
32
|
+
headerAuth: string;
|
|
33
|
+
headerAuthScheme: string;
|
|
34
|
+
query: string;
|
|
35
|
+
cookie: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
tempToken: {
|
|
39
|
+
signOptions: {
|
|
40
|
+
expiresIn: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
default: IJwtClientOptions;
|
|
44
|
+
clients: Record<keyof IJwtClientRecord, IJwtClientOptions>;
|
|
45
|
+
}
|
|
46
|
+
export interface IPayloadDataBase {
|
|
47
|
+
}
|
|
48
|
+
export interface IJwtPayload {
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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.
|
|
4
|
+
"version": "5.0.10",
|
|
5
5
|
"title": "a-jwt",
|
|
6
6
|
"vonaModule": {
|
|
7
7
|
"dependencies": {}
|
|
@@ -30,8 +30,12 @@
|
|
|
30
30
|
"jsonwebtoken": "^9.0.2",
|
|
31
31
|
"ms": "^2.1.3"
|
|
32
32
|
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"clean-package": "^2.2.0",
|
|
35
|
+
"rimraf": "^6.0.1"
|
|
36
|
+
},
|
|
33
37
|
"scripts": {
|
|
34
|
-
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
35
|
-
"tsc:publish": "npm run clean && tsc"
|
|
38
|
+
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
39
|
+
"tsc:publish": "npm run clean && tsc -p tsconfig.build.json"
|
|
36
40
|
}
|
|
37
41
|
}
|