@nathapp/nestjs-auth 1.0.0-rc.3 → 1.0.0-rc.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.
@@ -27,7 +27,7 @@ let JwtModule = JwtModule_1 = class JwtModule {
27
27
  provide: module_constant_1.AUTH_PROVIDER,
28
28
  useClass: options.authProvider,
29
29
  };
30
- let strategyProvider = this.createStrategyProvider(options);
30
+ const strategyProvider = this.createStrategyProvider(options);
31
31
  return {
32
32
  module: JwtModule_1,
33
33
  imports: [],
@@ -42,7 +42,7 @@ let JwtModule = JwtModule_1 = class JwtModule {
42
42
  provide: module_constant_1.AUTH_PROVIDER,
43
43
  useClass: options.authProvider,
44
44
  };
45
- let strategyProvider = this.createStrategyProvider(options);
45
+ const strategyProvider = this.createStrategyProvider(options);
46
46
  return {
47
47
  module: JwtModule_1,
48
48
  imports: options.imports || [],
@@ -1,10 +1,9 @@
1
1
  import { Strategy } from "passport-jwt";
2
- import { Request } from "express";
3
2
  import { JwtStrategyProvider } from "./strategy-provider";
4
3
  declare const JwtStrategy_base: new (...args: any[]) => Strategy;
5
4
  export declare class JwtStrategy extends JwtStrategy_base {
6
5
  private readonly strategyProvider;
7
6
  constructor(strategyProvider: JwtStrategyProvider);
8
- validate(req: Request, payload: any): Promise<import("..").IPrincipal>;
7
+ validate(arg1: any, arg2: any): Promise<import("..").IPrincipal>;
9
8
  }
10
9
  export {};
@@ -25,7 +25,9 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
25
25
  });
26
26
  this.strategyProvider = strategyProvider;
27
27
  }
28
- async validate(req, payload) {
28
+ async validate(arg1, arg2) {
29
+ const req = this.strategyProvider.passReqToCallback ? arg1 : {};
30
+ const payload = this.strategyProvider.passReqToCallback ? arg2 : arg1;
29
31
  return this.strategyProvider.validate(req, payload);
30
32
  }
31
33
  };
@@ -20,7 +20,10 @@ export interface StrategyProvider {
20
20
  export declare abstract class JwtStrategyProvider implements StrategyProvider {
21
21
  protected readonly jwtOptions: JwtOptions;
22
22
  private readonly jwtProvider;
23
- readonly secretOrPrivateKey: string | Buffer;
23
+ readonly secretOrPrivateKey: string | Buffer | {
24
+ key: string | Buffer;
25
+ passphrase: string;
26
+ };
24
27
  readonly secretOrPublicKey: string | Buffer;
25
28
  readonly jwtFromRequestFunction: JwtFromRequestFunction;
26
29
  readonly ignoreExpiration: boolean;
@@ -20,7 +20,9 @@ class JwtStrategyProvider {
20
20
  this.jwtProvider = new auth_1.JwtProvider(jwtOptions);
21
21
  this.secretOrPrivateKey = this.jwtProvider.secretOrPrivateKey;
22
22
  this.secretOrPublicKey = this.jwtProvider.secretOrPublicKey;
23
- this.jwtFromRequestFunction = jwtOptions.jwtFromRequestFunction || passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken();
23
+ this.jwtFromRequestFunction = this.jwtOptions.jwtFromRequestFunction || passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken();
24
+ this.ignoreExpiration = this.jwtOptions.ignoreExpiration;
25
+ this.passReqToCallback = this.jwtOptions.passReqToCallback;
24
26
  }
25
27
  sign(payload) {
26
28
  return this.jwtProvider.sign(payload);
@@ -39,9 +41,9 @@ class DefaultJwtStrategyProvider extends JwtStrategyProvider {
39
41
  async validate(req, payload) {
40
42
  const { checkBlacklisted, bindIp, allowDuplicateLogin } = this.jwtOptions;
41
43
  this.logger.debug(`validating Jwt request`);
42
- this.logger.debug(`payload: ${JSON.stringify(payload)}`);
44
+ this.logger.verbose(`payload: ${JSON.stringify(payload)}`);
43
45
  const principal = await this.authProvider.getPrincipal(payload);
44
- this.logger.debug(`principal: ${JSON.stringify(principal)}`);
46
+ this.logger.verbose(`principal: ${JSON.stringify(principal)}`);
45
47
  if (!principal) {
46
48
  throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.NOT_FOUND);
47
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-auth",
3
- "version": "1.0.0-rc.3",
3
+ "version": "1.0.0-rc.5",
4
4
  "description": "nestjs-auth",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc -p tsconfig.json",
@@ -32,7 +32,7 @@
32
32
  "lib": "lib"
33
33
  },
34
34
  "dependencies": {
35
- "@nathapp/auth": "^1.0.1-rc.1",
35
+ "@nathapp/auth": "^1.0.1-rc.2",
36
36
  "@nathapp/nestjs-common": "^1.0.1-rc.5",
37
37
  "passport-jwt": "^4.0.1"
38
38
  },