@midwayjs/jwt 3.0.2 → 3.0.5

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,14 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/jwt",
3
3
  "description": "midway jwt component",
4
- "version": "3.0.2",
4
+ "version": "3.0.5",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
8
8
  "dist/**/*.js",
9
9
  "dist/**/*.d.ts",
10
- "index.d.ts",
11
- "dist/**/*.js.map"
10
+ "index.d.ts"
12
11
  ],
13
12
  "scripts": {
14
13
  "build": "tsc",
@@ -23,16 +22,16 @@
23
22
  "author": "Nawbc",
24
23
  "license": "MIT",
25
24
  "devDependencies": {
26
- "@midwayjs/core": "^3.0.2",
27
- "@midwayjs/decorator": "^3.0.2",
28
- "@midwayjs/express": "^3.0.2",
29
- "@midwayjs/koa": "^3.0.2",
30
- "@midwayjs/mock": "^3.0.2",
31
- "@midwayjs/web": "^3.0.2",
25
+ "@midwayjs/core": "^3.0.4",
26
+ "@midwayjs/decorator": "^3.0.4",
27
+ "@midwayjs/express": "^3.0.5",
28
+ "@midwayjs/koa": "^3.0.5",
29
+ "@midwayjs/mock": "^3.0.5",
30
+ "@midwayjs/web": "^3.0.5",
32
31
  "@types/jsonwebtoken": "8.5.8"
33
32
  },
34
33
  "dependencies": {
35
34
  "jsonwebtoken": "^8.5.1"
36
35
  },
37
- "gitHead": "ca77247d229978a736e79bb208579c014ed226fc"
36
+ "gitHead": "9b17898f10faeef2e7f1011eaea67f1d0b085261"
38
37
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;AACA,mDAAoD;AACpD,+BAAmC;AAYnC,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IACpB,KAAK,CAAC,OAAO,CAAC,SAA0B;QAC7C,MAAM,SAAS,CAAC,QAAQ,CAAC,gBAAU,CAAC,CAAC;IACvC,CAAC;CACF,CAAA;AAJY,gBAAgB;IAV5B,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE;oBACP,GAAG,EAAE,EAAE;iBACR;aACF;SACF;KACF,CAAC;GACW,gBAAgB,CAI5B;AAJY,4CAAgB","sourcesContent":["import { MidwayContainer } from '@midwayjs/core';\nimport { Configuration } from '@midwayjs/decorator';\nimport { JwtService } from './jwt';\n\n@Configuration({\n namespace: 'jwt',\n importConfigs: [\n {\n default: {\n jwt: {},\n },\n },\n ],\n})\nexport class JwtConfiguration {\n public async onReady(container: MidwayContainer) {\n await container.getAsync(JwtService);\n }\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAAoE;AAA3D,8GAAA,gBAAgB,OAAiB;AAC1C,wCAAsB","sourcesContent":["export { JwtConfiguration as Configuration } from './configuration';\nexport * from './jwt';\n"]}
package/dist/jwt.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAwE;AASxE,oCAAoC;AAIpC;;;GAGG;AAGH,IAAa,UAAU,GAAvB,MAAa,UAAU;IAiBd,QAAQ,CACb,OAAmB,EACnB,kBAAuB,EACvB,OAAa;;QAEb,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,kBAAkB,CAAC;YAC7B,kBAAkB,GAAG,MAAA,IAAI,CAAC,SAAS,0CAAE,MAAM,CAAC;SAC7C;QACD,IAAI,CAAC,kBAAkB,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAC3D;QACD,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GA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orator';\nimport type {\n DecodeOptions,\n GetPublicKeyOrSecret,\n Jwt,\n Secret,\n SignOptions,\n VerifyOptions,\n} from 'jsonwebtoken';\nimport * as jwt from 'jsonwebtoken';\n\ntype JwtPayload = string | Buffer | Record<string, any>;\n\n/**\n *\n * @see{@link https://github.com/auth0/node-jsonwebtoken}\n */\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class JwtService {\n @Config('jwt')\n private jwtConfig: any;\n\n /**\n * Synchronously sign the given payload into a JSON Web Token string\n * payload - Payload to sign, could be an literal, buffer or string\n * secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA.\n * [options] - Options for the signature\n * returns - The JSON Web Token string\n */\n public signSync(payload: JwtPayload, options?: SignOptions): string;\n public signSync(\n payload: JwtPayload,\n secretOrPrivateKey: Secret,\n options?: SignOptions\n ): string;\n public signSync(\n payload: JwtPayload,\n secretOrPrivateKey: any,\n options?: any\n ): string {\n if (!options) {\n options = secretOrPrivateKey;\n secretOrPrivateKey = this.jwtConfig?.secret;\n }\n if (!secretOrPrivateKey) {\n throw new Error('[midway-jwt]: jwt secret should be set');\n }\n options = options ?? {};\n options.expiresIn = options.expiresIn ?? this.jwtConfig.expiresIn;\n\n return jwt.sign(payload, secretOrPrivateKey, options);\n }\n\n /**\n * Asynchronous sign the given payload into a JSON Web Token string\n * payload - Payload to sign, could be an literal, buffer or string\n * secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA.\n * [options] - Options for the signature\n * returns - The JSON Web Token string\n */\n public async sign(\n payload: JwtPayload,\n options?: SignOptions\n ): Promise<string>;\n public async sign(\n payload: JwtPayload,\n secretOrPrivateKey: Secret,\n options?: SignOptions\n ): Promise<string>;\n public async sign(\n payload: JwtPayload,\n secretOrPrivateKey: any,\n options?: any\n ): Promise<string> {\n if (!options) {\n options = secretOrPrivateKey;\n secretOrPrivateKey = this.jwtConfig?.secret;\n }\n if (!secretOrPrivateKey) {\n throw new Error('[midway-jwt]: provide the jwt secret please');\n }\n options = options ?? {};\n options.expiresIn = options.expiresIn ?? this.jwtConfig.expiresIn;\n\n return new Promise((resolve, reject) => {\n jwt.sign(payload, secretOrPrivateKey, options, (err, encoded) => {\n if (err) {\n reject(err);\n } else {\n resolve(encoded);\n }\n });\n });\n }\n\n /**\n * Synchronously verify given token using a secret or a public key to get a decoded token\n * token - JWT string to verify\n * secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA.\n * [options] - Options for the verification\n * returns - The decoded token.\n */\n public verifySync(\n token: string,\n options: VerifyOptions & { complete: true }\n ): Jwt | string;\n public verifySync(token: string, options: VerifyOptions): JwtPayload | string;\n public verifySync(\n token: string,\n secretOrPublicKey: Secret,\n options?: VerifyOptions & { complete: true }\n ): Jwt | string;\n public verifySync(\n token: string,\n secretOrPublicKey: Secret,\n options?: VerifyOptions\n ): JwtPayload | string;\n public verifySync(token: string, secretOrPublicKey: any, options?: any): any {\n if (!options) {\n options = secretOrPublicKey;\n secretOrPublicKey = this.jwtConfig?.secret;\n }\n\n if (!secretOrPublicKey) {\n throw new Error('[midway-jwt]: provide the jwt secret please');\n }\n\n return jwt.verify(token, secretOrPublicKey, options);\n }\n\n /**\n * Asynchronous verify given token using a secret or a public key to get a decoded token\n * token - JWT string to verify\n * secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA.\n * [options] - Options for the verification\n * returns - The decoded token.\n */\n public async verify(\n token: string,\n options?: VerifyOptions & { complete: true }\n ): Promise<Jwt | string>;\n public async verify(\n token: string,\n options?: VerifyOptions\n ): Promise<JwtPayload | string>;\n public async verify(\n token: string,\n secretOrPublicKey: Secret | GetPublicKeyOrSecret,\n options?: VerifyOptions & { complete: true }\n ): Promise<Jwt | string>;\n public async verify(\n token: string,\n secretOrPublicKey: Secret | GetPublicKeyOrSecret,\n options?: VerifyOptions\n ): Promise<JwtPayload | string>;\n public async verify(\n token: string,\n secretOrPublicKey: any,\n options?: any\n ): Promise<any> {\n if (!options) {\n options = secretOrPublicKey;\n secretOrPublicKey = this.jwtConfig?.secret;\n }\n\n if (!secretOrPublicKey) {\n throw new Error('[midway-jwt]: provide the jwt secret please');\n }\n\n return new Promise((resolve, reject) => {\n jwt.verify(token, secretOrPublicKey, options, (err, encoded) => {\n if (err) {\n reject(err);\n } else {\n resolve(encoded);\n }\n });\n });\n }\n\n /**\n * Returns the decoded payload without verifying if the signature is valid.\n * token - JWT string to decode\n * [options] - Options for decoding\n * returns - The decoded Token\n */\n public decode(\n token: string,\n options: DecodeOptions & { complete: true }\n ): null | Jwt;\n public decode(\n token: string,\n options: DecodeOptions & { json: true }\n ): null | JwtPayload;\n public decode(\n token: string,\n options?: DecodeOptions\n ): null | JwtPayload | string;\n public decode(token: string, options?: any): any {\n return jwt.decode(token, options);\n }\n\n /**\n * alias decode method\n * @param token\n * @param options\n */\n public decodeSync(\n token: string,\n options: DecodeOptions & { complete: true }\n ): null | Jwt;\n public decodeSync(\n token: string,\n options: DecodeOptions & { json: true }\n ): null | JwtPayload;\n public decodeSync(\n token: string,\n options?: DecodeOptions\n ): null | JwtPayload | string;\n public decodeSync(token: string, options?: any): any {\n return this.decode(token, options);\n }\n}\n"]}