1 |
|
2 | import { AnyObject, ErrorData, JWTString } from '@naturalcycles/js-lib';
|
3 | import type { Algorithm, VerifyOptions, JwtHeader, SignOptions } from 'jsonwebtoken';
|
4 | import * as jsonwebtoken from 'jsonwebtoken';
|
5 | import { AnySchemaTyped } from '../validation/joi/joi.model';
|
6 | export { jsonwebtoken };
|
7 | export type { Algorithm, VerifyOptions, SignOptions, JwtHeader };
|
8 | export interface JWTServiceCfg {
|
9 | |
10 |
|
11 |
|
12 |
|
13 | publicKey?: string | Buffer;
|
14 | |
15 |
|
16 |
|
17 |
|
18 | privateKey?: string | Buffer;
|
19 | |
20 |
|
21 |
|
22 | algorithm: Algorithm;
|
23 | |
24 |
|
25 |
|
26 | signOptions?: SignOptions;
|
27 | |
28 |
|
29 |
|
30 | verifyOptions?: VerifyOptions;
|
31 | |
32 |
|
33 |
|
34 |
|
35 | errorData?: ErrorData;
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | export declare class JWTService {
|
46 | cfg: JWTServiceCfg;
|
47 | constructor(cfg: JWTServiceCfg);
|
48 | sign<T extends AnyObject>(payload: T, schema?: AnySchemaTyped<T>, opt?: SignOptions): JWTString;
|
49 | verify<T extends AnyObject>(token: JWTString, schema?: AnySchemaTyped<T>, opt?: VerifyOptions): T;
|
50 | decode<T extends AnyObject>(token: JWTString, schema?: AnySchemaTyped<T>): {
|
51 | header: JwtHeader;
|
52 | payload: T;
|
53 | signature: string;
|
54 | };
|
55 | }
|