@nathapp/nestjs-auth 1.0.0-rc.8 → 1.0.0-rc.9
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/constant/index.d.ts +2 -2
- package/dist/constant/index.js +3 -1
- package/dist/constant/jwt-constant.d.ts +3 -1
- package/dist/constant/jwt-constant.js +4 -2
- package/dist/guard/index.d.ts +2 -1
- package/dist/guard/index.js +3 -1
- package/dist/guard/jwt-refresh.guard.d.ts +4 -0
- package/dist/guard/jwt-refresh.guard.js +18 -0
- package/dist/module/jwt-module.d.ts +8 -3
- package/dist/module/jwt-module.js +36 -9
- package/dist/strategy/index.d.ts +5 -2
- package/dist/strategy/index.js +10 -5
- package/dist/strategy/jwt-refresh-strategy-provider.d.ts +23 -0
- package/dist/strategy/jwt-refresh-strategy-provider.js +47 -0
- package/dist/strategy/jwt-refresh-strategy.d.ts +9 -0
- package/dist/strategy/jwt-refresh-strategy.js +38 -0
- package/dist/strategy/jwt-strategy-provider.d.ts +28 -0
- package/dist/strategy/jwt-strategy-provider.js +88 -0
- package/dist/strategy/jwt-strategy.d.ts +1 -1
- package/dist/strategy/jwt-strategy.js +2 -2
- package/dist/strategy/strategy-provider.d.ts +1 -23
- package/dist/strategy/strategy-provider.js +0 -80
- package/package.json +3 -3
package/dist/constant/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { JWT_STRATEGY_NAME, JWT_API_STRATEGY_NAME, JWT_GRPC_STRATEGY_NAME } from "./jwt-constant";
|
|
1
|
+
import { JWT_STRATEGY_NAME, JWT_API_STRATEGY_NAME, JWT_GRPC_STRATEGY_NAME, JWT_REFRESH_TOKEN_KEY, JWT_REFRESH_STRATEGY_NAME } from "./jwt-constant";
|
|
2
2
|
import { AUTH_PROVIDER, JWT_OPTIONS, JWT_PROVIDER, STRATEGY_PROVIDER } from "./module-constant";
|
|
3
|
-
export { JWT_STRATEGY_NAME, JWT_API_STRATEGY_NAME, JWT_GRPC_STRATEGY_NAME, JWT_OPTIONS, STRATEGY_PROVIDER, AUTH_PROVIDER, JWT_PROVIDER, };
|
|
3
|
+
export { JWT_STRATEGY_NAME, JWT_REFRESH_STRATEGY_NAME, JWT_API_STRATEGY_NAME, JWT_GRPC_STRATEGY_NAME, JWT_REFRESH_TOKEN_KEY, JWT_OPTIONS, STRATEGY_PROVIDER, AUTH_PROVIDER, JWT_PROVIDER, };
|
package/dist/constant/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JWT_PROVIDER = exports.AUTH_PROVIDER = exports.STRATEGY_PROVIDER = exports.JWT_OPTIONS = exports.JWT_GRPC_STRATEGY_NAME = exports.JWT_API_STRATEGY_NAME = exports.JWT_STRATEGY_NAME = void 0;
|
|
3
|
+
exports.JWT_PROVIDER = exports.AUTH_PROVIDER = exports.STRATEGY_PROVIDER = exports.JWT_OPTIONS = exports.JWT_REFRESH_TOKEN_KEY = exports.JWT_GRPC_STRATEGY_NAME = exports.JWT_API_STRATEGY_NAME = exports.JWT_REFRESH_STRATEGY_NAME = exports.JWT_STRATEGY_NAME = void 0;
|
|
4
4
|
const jwt_constant_1 = require("./jwt-constant");
|
|
5
5
|
Object.defineProperty(exports, "JWT_STRATEGY_NAME", { enumerable: true, get: function () { return jwt_constant_1.JWT_STRATEGY_NAME; } });
|
|
6
6
|
Object.defineProperty(exports, "JWT_API_STRATEGY_NAME", { enumerable: true, get: function () { return jwt_constant_1.JWT_API_STRATEGY_NAME; } });
|
|
7
7
|
Object.defineProperty(exports, "JWT_GRPC_STRATEGY_NAME", { enumerable: true, get: function () { return jwt_constant_1.JWT_GRPC_STRATEGY_NAME; } });
|
|
8
|
+
Object.defineProperty(exports, "JWT_REFRESH_TOKEN_KEY", { enumerable: true, get: function () { return jwt_constant_1.JWT_REFRESH_TOKEN_KEY; } });
|
|
9
|
+
Object.defineProperty(exports, "JWT_REFRESH_STRATEGY_NAME", { enumerable: true, get: function () { return jwt_constant_1.JWT_REFRESH_STRATEGY_NAME; } });
|
|
8
10
|
const module_constant_1 = require("./module-constant");
|
|
9
11
|
Object.defineProperty(exports, "AUTH_PROVIDER", { enumerable: true, get: function () { return module_constant_1.AUTH_PROVIDER; } });
|
|
10
12
|
Object.defineProperty(exports, "JWT_OPTIONS", { enumerable: true, get: function () { return module_constant_1.JWT_OPTIONS; } });
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const JWT_STRATEGY_NAME = "JWT";
|
|
2
|
+
export declare const JWT_REFRESH_STRATEGY_NAME = "REFRESH-JWT";
|
|
2
3
|
export declare const JWT_API_STRATEGY_NAME = "API-JWT";
|
|
3
|
-
export declare const JWT_GRPC_STRATEGY_NAME = "GRPC";
|
|
4
|
+
export declare const JWT_GRPC_STRATEGY_NAME = "GRPC-JWT";
|
|
5
|
+
export declare const JWT_REFRESH_TOKEN_KEY = "refresh_token";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JWT_GRPC_STRATEGY_NAME = exports.JWT_API_STRATEGY_NAME = exports.JWT_STRATEGY_NAME = void 0;
|
|
3
|
+
exports.JWT_REFRESH_TOKEN_KEY = exports.JWT_GRPC_STRATEGY_NAME = exports.JWT_API_STRATEGY_NAME = exports.JWT_REFRESH_STRATEGY_NAME = exports.JWT_STRATEGY_NAME = void 0;
|
|
4
4
|
exports.JWT_STRATEGY_NAME = "JWT";
|
|
5
|
+
exports.JWT_REFRESH_STRATEGY_NAME = "REFRESH-JWT";
|
|
5
6
|
exports.JWT_API_STRATEGY_NAME = "API-JWT";
|
|
6
|
-
exports.JWT_GRPC_STRATEGY_NAME = "GRPC";
|
|
7
|
+
exports.JWT_GRPC_STRATEGY_NAME = "GRPC-JWT";
|
|
8
|
+
exports.JWT_REFRESH_TOKEN_KEY = "refresh_token";
|
package/dist/guard/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { JwtAuthGuard } from "./jwt-auth.guard";
|
|
2
|
+
import { JwtRefreshGuard } from "./jwt-refresh.guard";
|
|
2
3
|
import { PermissionAuthGuard } from "./permission-auth.guard";
|
|
3
|
-
export { JwtAuthGuard, PermissionAuthGuard, };
|
|
4
|
+
export { JwtAuthGuard, JwtRefreshGuard, PermissionAuthGuard, };
|
package/dist/guard/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PermissionAuthGuard = exports.JwtAuthGuard = void 0;
|
|
3
|
+
exports.PermissionAuthGuard = exports.JwtRefreshGuard = exports.JwtAuthGuard = void 0;
|
|
4
4
|
const jwt_auth_guard_1 = require("./jwt-auth.guard");
|
|
5
5
|
Object.defineProperty(exports, "JwtAuthGuard", { enumerable: true, get: function () { return jwt_auth_guard_1.JwtAuthGuard; } });
|
|
6
|
+
const jwt_refresh_guard_1 = require("./jwt-refresh.guard");
|
|
7
|
+
Object.defineProperty(exports, "JwtRefreshGuard", { enumerable: true, get: function () { return jwt_refresh_guard_1.JwtRefreshGuard; } });
|
|
6
8
|
const permission_auth_guard_1 = require("./permission-auth.guard");
|
|
7
9
|
Object.defineProperty(exports, "PermissionAuthGuard", { enumerable: true, get: function () { return permission_auth_guard_1.PermissionAuthGuard; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.JwtRefreshGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
const jwt_constant_1 = require("../constant/jwt-constant");
|
|
13
|
+
let JwtRefreshGuard = class JwtRefreshGuard extends (0, passport_1.AuthGuard)(jwt_constant_1.JWT_REFRESH_STRATEGY_NAME) {
|
|
14
|
+
};
|
|
15
|
+
JwtRefreshGuard = __decorate([
|
|
16
|
+
(0, common_1.Injectable)()
|
|
17
|
+
], JwtRefreshGuard);
|
|
18
|
+
exports.JwtRefreshGuard = JwtRefreshGuard;
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { DynamicModule, ModuleMetadata, Type } from '@nestjs/common';
|
|
2
2
|
import { AuthProvider } from '../auth-provider';
|
|
3
|
-
import { JwtOptions, JwtStrategyProvider } from '../strategy';
|
|
3
|
+
import { JwtOptions, JwtRefreshStrategyProvider, JwtStrategyProvider } from '../strategy';
|
|
4
4
|
import { ConfigService } from '@nestjs/config';
|
|
5
5
|
export declare class JwtModule {
|
|
6
6
|
static forRoot(options: JwtModuleOptions): DynamicModule;
|
|
7
7
|
static forRootAsync(options: JwtModuleAsyncOptions): DynamicModule;
|
|
8
|
-
private static
|
|
8
|
+
private static sanitizeJwtModuleOptions;
|
|
9
9
|
private static createStrategyProvider;
|
|
10
|
+
private static createRefreshStrategyProvider;
|
|
11
|
+
private static sanitizeJwtRefreshOption;
|
|
10
12
|
private static createAsyncOptionsProviders;
|
|
11
13
|
private static createAsyncOptionsProvider;
|
|
12
14
|
}
|
|
13
|
-
export type JwtModuleOptionsWithoutProvider = Omit<JwtModuleOptions, 'authProvider' | 'strategyProvider'>;
|
|
15
|
+
export type JwtModuleOptionsWithoutProvider = Omit<JwtModuleOptions, 'authProvider' | 'strategyProvider' | 'refreshStrategyProvider'>;
|
|
14
16
|
export interface JwtModuleOptions {
|
|
15
17
|
jwtOptions: JwtOptions;
|
|
18
|
+
refreshJwtOptions?: JwtOptions;
|
|
16
19
|
logging?: boolean;
|
|
17
20
|
authProvider?: Type<AuthProvider>;
|
|
18
21
|
strategyProvider?: Type<JwtStrategyProvider>;
|
|
22
|
+
refreshStrategyProvider?: Type<JwtRefreshStrategyProvider>;
|
|
19
23
|
}
|
|
20
24
|
export interface JwtModuleOptionsFactory {
|
|
21
25
|
createOptions(): Promise<JwtModuleOptionsWithoutProvider> | JwtModuleOptionsWithoutProvider;
|
|
@@ -27,6 +31,7 @@ export interface JwtModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
|
27
31
|
useFactory?: (...args: any[]) => JwtModuleOptionsWithoutProvider | Promise<JwtModuleOptionsWithoutProvider>;
|
|
28
32
|
authProvider?: Type<AuthProvider>;
|
|
29
33
|
strategyProvider?: Type<JwtStrategyProvider>;
|
|
34
|
+
refreshStrategyProvider?: Type<JwtRefreshStrategyProvider>;
|
|
30
35
|
inject?: any[];
|
|
31
36
|
}
|
|
32
37
|
export declare class DefaultJwtModuleOptionsFactory implements JwtModuleOptionsFactory {
|
|
@@ -23,7 +23,7 @@ const defaultOptions = {
|
|
|
23
23
|
};
|
|
24
24
|
let JwtModule = JwtModule_1 = class JwtModule {
|
|
25
25
|
static forRoot(options) {
|
|
26
|
-
options = this.
|
|
26
|
+
options = this.sanitizeJwtModuleOptions(options);
|
|
27
27
|
const jwtOptions = {
|
|
28
28
|
provide: module_constant_1.JWT_OPTIONS,
|
|
29
29
|
useValue: options,
|
|
@@ -33,29 +33,31 @@ let JwtModule = JwtModule_1 = class JwtModule {
|
|
|
33
33
|
useClass: options.authProvider,
|
|
34
34
|
};
|
|
35
35
|
const strategyProvider = this.createStrategyProvider(options);
|
|
36
|
+
const refreshStrategyProvider = this.createRefreshStrategyProvider(options);
|
|
36
37
|
return {
|
|
37
38
|
module: JwtModule_1,
|
|
38
39
|
imports: [],
|
|
39
|
-
providers: [jwtOptions, authProvider, strategyProvider],
|
|
40
|
-
exports: [module_constant_1.JWT_OPTIONS, strategyProvider],
|
|
40
|
+
providers: [jwtOptions, authProvider, strategyProvider, refreshStrategyProvider],
|
|
41
|
+
exports: [module_constant_1.JWT_OPTIONS, strategyProvider, refreshStrategyProvider],
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
static forRootAsync(options) {
|
|
44
|
-
options = this.
|
|
45
|
+
options = this.sanitizeJwtModuleOptions(options);
|
|
45
46
|
const asyncOptionsProviders = this.createAsyncOptionsProviders(options);
|
|
46
47
|
const authProvider = {
|
|
47
48
|
provide: module_constant_1.AUTH_PROVIDER,
|
|
48
49
|
useClass: options.authProvider,
|
|
49
50
|
};
|
|
50
51
|
const strategyProvider = this.createStrategyProvider(options);
|
|
52
|
+
const refreshStrategyProvider = this.createRefreshStrategyProvider(options);
|
|
51
53
|
return {
|
|
52
54
|
module: JwtModule_1,
|
|
53
55
|
imports: options.imports || [],
|
|
54
|
-
providers: [...asyncOptionsProviders, authProvider, strategyProvider],
|
|
55
|
-
exports: [module_constant_1.JWT_OPTIONS, strategyProvider],
|
|
56
|
+
providers: [...asyncOptionsProviders, authProvider, strategyProvider, refreshStrategyProvider],
|
|
57
|
+
exports: [module_constant_1.JWT_OPTIONS, strategyProvider, refreshStrategyProvider],
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
|
-
static
|
|
60
|
+
static sanitizeJwtModuleOptions(options) {
|
|
59
61
|
options = { ...defaultOptions, ...options };
|
|
60
62
|
return options;
|
|
61
63
|
}
|
|
@@ -76,6 +78,31 @@ let JwtModule = JwtModule_1 = class JwtModule {
|
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
80
|
}
|
|
81
|
+
static createRefreshStrategyProvider(options) {
|
|
82
|
+
if (options.refreshStrategyProvider) {
|
|
83
|
+
return {
|
|
84
|
+
provide: strategy_1.JwtRefreshStrategyProvider,
|
|
85
|
+
useClass: options.refreshStrategyProvider,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return {
|
|
90
|
+
provide: strategy_1.JwtRefreshStrategyProvider,
|
|
91
|
+
useFactory: async (options) => {
|
|
92
|
+
return new strategy_1.DefaultJwtRefreshStrategyProvider(this.sanitizeJwtRefreshOption(options.refreshJwtOptions, options.jwtOptions));
|
|
93
|
+
},
|
|
94
|
+
inject: [module_constant_1.JWT_OPTIONS],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
static sanitizeJwtRefreshOption(refreshOption, jwtOption) {
|
|
99
|
+
if ((0, common_1.isUndefinedOrNullOrEmpty)(refreshOption === null || refreshOption === void 0 ? void 0 : refreshOption.secret) &&
|
|
100
|
+
(0, common_1.isUndefinedOrNullOrEmpty)(refreshOption === null || refreshOption === void 0 ? void 0 : refreshOption.privateKey) &&
|
|
101
|
+
(0, common_1.isUndefinedOrNullOrEmpty)(refreshOption === null || refreshOption === void 0 ? void 0 : refreshOption.publicKey)) {
|
|
102
|
+
refreshOption = jwtOption;
|
|
103
|
+
}
|
|
104
|
+
return refreshOption;
|
|
105
|
+
}
|
|
79
106
|
static createAsyncOptionsProviders(options) {
|
|
80
107
|
if (options.useExisting || options.useFactory) {
|
|
81
108
|
return [this.createAsyncOptionsProvider(options)];
|
|
@@ -93,14 +120,14 @@ let JwtModule = JwtModule_1 = class JwtModule {
|
|
|
93
120
|
return {
|
|
94
121
|
provide: module_constant_1.JWT_OPTIONS,
|
|
95
122
|
useFactory: async (...args) => {
|
|
96
|
-
return this.
|
|
123
|
+
return this.sanitizeJwtModuleOptions((await options.useFactory(...args)));
|
|
97
124
|
},
|
|
98
125
|
inject: options.inject || [],
|
|
99
126
|
};
|
|
100
127
|
}
|
|
101
128
|
return {
|
|
102
129
|
provide: module_constant_1.JWT_OPTIONS,
|
|
103
|
-
useFactory: async (optionsFactory) => this.
|
|
130
|
+
useFactory: async (optionsFactory) => this.sanitizeJwtModuleOptions((await optionsFactory.createOptions())),
|
|
104
131
|
inject: [options.useClass || options.useExisting]
|
|
105
132
|
};
|
|
106
133
|
}
|
package/dist/strategy/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { JwtRefreshStrategy } from "./jwt-refresh-strategy";
|
|
2
|
+
import { DefaultJwtRefreshStrategyProvider, JwtRefreshStrategyProvider } from "./jwt-refresh-strategy-provider";
|
|
1
3
|
import { JwtStrategy } from "./jwt-strategy";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
+
import { DefaultJwtStrategyProvider, JwtStrategyProvider, SimpleJwtStrategyProvider } from "./jwt-strategy-provider";
|
|
5
|
+
import { StrategyProvider, JwtOptions } from "./strategy-provider";
|
|
6
|
+
export { JwtOptions, StrategyProvider, JwtStrategyProvider, DefaultJwtStrategyProvider, SimpleJwtStrategyProvider, JwtRefreshStrategyProvider, DefaultJwtRefreshStrategyProvider, JwtStrategy, JwtRefreshStrategy, };
|
package/dist/strategy/index.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JwtStrategy = exports.SimpleJwtStrategyProvider = exports.DefaultJwtStrategyProvider = exports.JwtStrategyProvider = void 0;
|
|
3
|
+
exports.JwtRefreshStrategy = exports.JwtStrategy = exports.DefaultJwtRefreshStrategyProvider = exports.JwtRefreshStrategyProvider = exports.SimpleJwtStrategyProvider = exports.DefaultJwtStrategyProvider = exports.JwtStrategyProvider = void 0;
|
|
4
|
+
const jwt_refresh_strategy_1 = require("./jwt-refresh-strategy");
|
|
5
|
+
Object.defineProperty(exports, "JwtRefreshStrategy", { enumerable: true, get: function () { return jwt_refresh_strategy_1.JwtRefreshStrategy; } });
|
|
6
|
+
const jwt_refresh_strategy_provider_1 = require("./jwt-refresh-strategy-provider");
|
|
7
|
+
Object.defineProperty(exports, "DefaultJwtRefreshStrategyProvider", { enumerable: true, get: function () { return jwt_refresh_strategy_provider_1.DefaultJwtRefreshStrategyProvider; } });
|
|
8
|
+
Object.defineProperty(exports, "JwtRefreshStrategyProvider", { enumerable: true, get: function () { return jwt_refresh_strategy_provider_1.JwtRefreshStrategyProvider; } });
|
|
4
9
|
const jwt_strategy_1 = require("./jwt-strategy");
|
|
5
10
|
Object.defineProperty(exports, "JwtStrategy", { enumerable: true, get: function () { return jwt_strategy_1.JwtStrategy; } });
|
|
6
|
-
const
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
Object.defineProperty(exports, "
|
|
9
|
-
Object.defineProperty(exports, "SimpleJwtStrategyProvider", { enumerable: true, get: function () { return
|
|
11
|
+
const jwt_strategy_provider_1 = require("./jwt-strategy-provider");
|
|
12
|
+
Object.defineProperty(exports, "DefaultJwtStrategyProvider", { enumerable: true, get: function () { return jwt_strategy_provider_1.DefaultJwtStrategyProvider; } });
|
|
13
|
+
Object.defineProperty(exports, "JwtStrategyProvider", { enumerable: true, get: function () { return jwt_strategy_provider_1.JwtStrategyProvider; } });
|
|
14
|
+
Object.defineProperty(exports, "SimpleJwtStrategyProvider", { enumerable: true, get: function () { return jwt_strategy_provider_1.SimpleJwtStrategyProvider; } });
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { JwtOptions, StrategyProvider } from "./strategy-provider";
|
|
3
|
+
import * as jwt from 'jsonwebtoken';
|
|
4
|
+
import { JwtFromRequestFunction } from "passport-jwt";
|
|
5
|
+
import { IPrincipal } from "../auth-provider";
|
|
6
|
+
import { Request } from "express";
|
|
7
|
+
export declare abstract class JwtRefreshStrategyProvider implements StrategyProvider {
|
|
8
|
+
protected readonly jwtOptions: JwtOptions;
|
|
9
|
+
private readonly jwtProvider;
|
|
10
|
+
readonly secretOrPrivateKey: jwt.Secret;
|
|
11
|
+
readonly secretOrPublicKey: jwt.Secret;
|
|
12
|
+
readonly jwtFromRequestFunction: JwtFromRequestFunction;
|
|
13
|
+
readonly ignoreExpiration: boolean;
|
|
14
|
+
readonly passReqToCallback: boolean;
|
|
15
|
+
constructor(jwtOptions: JwtOptions);
|
|
16
|
+
sign(payload: string | object | Buffer): string;
|
|
17
|
+
verify(token: string, verifyOption?: jwt.VerifyOptions): string | object;
|
|
18
|
+
abstract validate(req: Request, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
19
|
+
}
|
|
20
|
+
export declare class DefaultJwtRefreshStrategyProvider extends JwtRefreshStrategyProvider {
|
|
21
|
+
constructor(jwtOptions: JwtOptions);
|
|
22
|
+
validate(req: Request, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultJwtRefreshStrategyProvider = exports.JwtRefreshStrategyProvider = void 0;
|
|
4
|
+
const auth_1 = require("@nathapp/auth");
|
|
5
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
6
|
+
const constant_1 = require("../constant");
|
|
7
|
+
class JwtRefreshStrategyProvider {
|
|
8
|
+
constructor(jwtOptions) {
|
|
9
|
+
const extraOptions = {
|
|
10
|
+
bindIp: false,
|
|
11
|
+
allowDuplicateLogin: false,
|
|
12
|
+
checkBlacklisted: false,
|
|
13
|
+
ignoreExpiration: false,
|
|
14
|
+
passReqToCallback: true,
|
|
15
|
+
};
|
|
16
|
+
this.jwtOptions = Object.assign({}, extraOptions, jwtOptions);
|
|
17
|
+
this.jwtProvider = new auth_1.JwtProvider(jwtOptions);
|
|
18
|
+
this.secretOrPrivateKey = this.jwtProvider.secretOrPrivateKey;
|
|
19
|
+
this.secretOrPublicKey = this.jwtProvider.secretOrPublicKey;
|
|
20
|
+
this.jwtFromRequestFunction = this.jwtOptions.jwtFromRequestFunction || passport_jwt_1.ExtractJwt.fromBodyField(constant_1.JWT_REFRESH_TOKEN_KEY);
|
|
21
|
+
this.ignoreExpiration = this.jwtOptions.ignoreExpiration;
|
|
22
|
+
this.passReqToCallback = this.jwtOptions.passReqToCallback;
|
|
23
|
+
}
|
|
24
|
+
sign(payload) {
|
|
25
|
+
return this.jwtProvider.sign(payload);
|
|
26
|
+
}
|
|
27
|
+
verify(token, verifyOption) {
|
|
28
|
+
return this.jwtProvider.verify(token, verifyOption);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.JwtRefreshStrategyProvider = JwtRefreshStrategyProvider;
|
|
32
|
+
class DefaultJwtRefreshStrategyProvider extends JwtRefreshStrategyProvider {
|
|
33
|
+
constructor(jwtOptions) {
|
|
34
|
+
super(jwtOptions);
|
|
35
|
+
}
|
|
36
|
+
validate(req, payload) {
|
|
37
|
+
return Promise.resolve({
|
|
38
|
+
id: payload.sub,
|
|
39
|
+
username: payload.username,
|
|
40
|
+
name: payload.name,
|
|
41
|
+
blacklisted: false,
|
|
42
|
+
revoked: false,
|
|
43
|
+
authorities: payload.authorities || [],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.DefaultJwtRefreshStrategyProvider = DefaultJwtRefreshStrategyProvider;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Strategy } from 'passport-jwt';
|
|
2
|
+
import { JwtRefreshStrategyProvider } from './jwt-refresh-strategy-provider';
|
|
3
|
+
declare const JwtRefreshStrategy_base: new (...args: any[]) => Strategy;
|
|
4
|
+
export declare class JwtRefreshStrategy extends JwtRefreshStrategy_base {
|
|
5
|
+
private readonly strategyProvider;
|
|
6
|
+
constructor(strategyProvider: JwtRefreshStrategyProvider);
|
|
7
|
+
validate(arg1: any, arg2: any): Promise<import("..").IPrincipal>;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JwtRefreshStrategy = void 0;
|
|
13
|
+
const passport_1 = require("@nestjs/passport");
|
|
14
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const jwt_constant_1 = require("../constant/jwt-constant");
|
|
17
|
+
const jwt_refresh_strategy_provider_1 = require("./jwt-refresh-strategy-provider");
|
|
18
|
+
let JwtRefreshStrategy = class JwtRefreshStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, jwt_constant_1.JWT_REFRESH_STRATEGY_NAME) {
|
|
19
|
+
constructor(strategyProvider) {
|
|
20
|
+
super({
|
|
21
|
+
jwtFromRequest: strategyProvider.jwtFromRequestFunction,
|
|
22
|
+
ignoreExpiration: strategyProvider.ignoreExpiration,
|
|
23
|
+
secretOrKey: strategyProvider.secretOrPublicKey,
|
|
24
|
+
passReqToCallback: strategyProvider.passReqToCallback,
|
|
25
|
+
});
|
|
26
|
+
this.strategyProvider = strategyProvider;
|
|
27
|
+
}
|
|
28
|
+
async validate(arg1, arg2) {
|
|
29
|
+
const req = this.strategyProvider.passReqToCallback ? arg1 : {};
|
|
30
|
+
const payload = this.strategyProvider.passReqToCallback ? arg2 : arg1;
|
|
31
|
+
return this.strategyProvider.validate(req, payload);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
JwtRefreshStrategy = __decorate([
|
|
35
|
+
(0, common_1.Injectable)(),
|
|
36
|
+
__metadata("design:paramtypes", [jwt_refresh_strategy_provider_1.JwtRefreshStrategyProvider])
|
|
37
|
+
], JwtRefreshStrategy);
|
|
38
|
+
exports.JwtRefreshStrategy = JwtRefreshStrategy;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { JwtFromRequestFunction } from "passport-jwt";
|
|
3
|
+
import { IPrincipal, AuthProvider } from "../auth-provider";
|
|
4
|
+
import { JwtOptions, StrategyProvider } from "./strategy-provider";
|
|
5
|
+
import * as jwt from 'jsonwebtoken';
|
|
6
|
+
import { Request } from "express";
|
|
7
|
+
export declare abstract class JwtStrategyProvider implements StrategyProvider {
|
|
8
|
+
protected readonly jwtOptions: JwtOptions;
|
|
9
|
+
private readonly jwtProvider;
|
|
10
|
+
readonly secretOrPrivateKey: jwt.Secret;
|
|
11
|
+
readonly secretOrPublicKey: jwt.Secret;
|
|
12
|
+
readonly jwtFromRequestFunction: JwtFromRequestFunction;
|
|
13
|
+
readonly ignoreExpiration: boolean;
|
|
14
|
+
readonly passReqToCallback: boolean;
|
|
15
|
+
constructor(jwtOptions: JwtOptions);
|
|
16
|
+
sign(payload: string | object | Buffer): string;
|
|
17
|
+
verify(token: string, verifyOption?: jwt.VerifyOptions): string | object;
|
|
18
|
+
abstract validate(req: Request, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
19
|
+
}
|
|
20
|
+
export declare class DefaultJwtStrategyProvider extends JwtStrategyProvider {
|
|
21
|
+
private readonly authProvider;
|
|
22
|
+
private readonly logger;
|
|
23
|
+
constructor(jwtOptions: JwtOptions, authProvider: AuthProvider);
|
|
24
|
+
validate(req: Request, payload: any): Promise<IPrincipal>;
|
|
25
|
+
}
|
|
26
|
+
export declare class SimpleJwtStrategyProvider extends DefaultJwtStrategyProvider {
|
|
27
|
+
constructor(jwtOptions: JwtOptions);
|
|
28
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleJwtStrategyProvider = exports.DefaultJwtStrategyProvider = exports.JwtStrategyProvider = void 0;
|
|
4
|
+
const auth_1 = require("@nathapp/auth");
|
|
5
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
8
|
+
const auth_provider_1 = require("../auth-provider");
|
|
9
|
+
const requestIp = require("request-ip");
|
|
10
|
+
class JwtStrategyProvider {
|
|
11
|
+
constructor(jwtOptions) {
|
|
12
|
+
const extraOptions = {
|
|
13
|
+
bindIp: false,
|
|
14
|
+
allowDuplicateLogin: true,
|
|
15
|
+
checkBlacklisted: true,
|
|
16
|
+
ignoreExpiration: false,
|
|
17
|
+
passReqToCallback: true,
|
|
18
|
+
};
|
|
19
|
+
this.jwtOptions = Object.assign({}, extraOptions, jwtOptions);
|
|
20
|
+
this.jwtProvider = new auth_1.JwtProvider(jwtOptions);
|
|
21
|
+
this.secretOrPrivateKey = this.jwtProvider.secretOrPrivateKey;
|
|
22
|
+
this.secretOrPublicKey = this.jwtProvider.secretOrPublicKey;
|
|
23
|
+
this.jwtFromRequestFunction = this.jwtOptions.jwtFromRequestFunction || passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken();
|
|
24
|
+
this.ignoreExpiration = this.jwtOptions.ignoreExpiration;
|
|
25
|
+
this.passReqToCallback = this.jwtOptions.passReqToCallback;
|
|
26
|
+
}
|
|
27
|
+
sign(payload) {
|
|
28
|
+
return this.jwtProvider.sign(payload);
|
|
29
|
+
}
|
|
30
|
+
verify(token, verifyOption) {
|
|
31
|
+
return this.jwtProvider.verify(token, verifyOption);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.JwtStrategyProvider = JwtStrategyProvider;
|
|
35
|
+
class DefaultJwtStrategyProvider extends JwtStrategyProvider {
|
|
36
|
+
constructor(jwtOptions, authProvider) {
|
|
37
|
+
super(jwtOptions);
|
|
38
|
+
this.authProvider = authProvider;
|
|
39
|
+
this.logger = new common_1.Logger(DefaultJwtStrategyProvider.name);
|
|
40
|
+
}
|
|
41
|
+
async validate(req, payload) {
|
|
42
|
+
const { checkBlacklisted, bindIp, allowDuplicateLogin, passReqToCallback } = this.jwtOptions;
|
|
43
|
+
this.logger.debug(`validating Jwt request`);
|
|
44
|
+
this.logger.verbose(`payload: ${JSON.stringify(payload)}`);
|
|
45
|
+
const principal = await this.authProvider.getPrincipal(payload);
|
|
46
|
+
this.logger.verbose(`principal: ${JSON.stringify(principal)}`);
|
|
47
|
+
if (!principal) {
|
|
48
|
+
this.logger.debug(`principal: not found. payload: ${JSON.stringify(payload)}`);
|
|
49
|
+
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.UNAUTHORIZED);
|
|
50
|
+
}
|
|
51
|
+
if (principal.revoked) {
|
|
52
|
+
this.logger.warn(`principal: ${principal.id} has revoked.`);
|
|
53
|
+
this.logger.debug(`principal: ${principal.id} has revoked. token: ${principal.hashToken}`);
|
|
54
|
+
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.UNAUTHORIZED);
|
|
55
|
+
}
|
|
56
|
+
if (checkBlacklisted && principal.blacklisted) {
|
|
57
|
+
this.logger.warn(`principal: ${principal.id} was blacklisted.`);
|
|
58
|
+
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.FORBIDDEN_BLACKLISTED);
|
|
59
|
+
}
|
|
60
|
+
if (bindIp) {
|
|
61
|
+
if (!req && !passReqToCallback) {
|
|
62
|
+
this.logger.warn(`req is undefined, are you using ExpressJs? if yes please set passReqToCallback to true, bindIp check is ignored`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const reqIp = requestIp.getClientIp(req);
|
|
66
|
+
if (!principal.loginIP || principal.loginIP != reqIp) {
|
|
67
|
+
this.logger.debug(`principal: ${principal.id} is from different IP.`);
|
|
68
|
+
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.FORBIDDEN_IP_NOT_MATCH);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!allowDuplicateLogin) {
|
|
73
|
+
const duplicated = await this.authProvider.isDuplicateLogin(principal, payload);
|
|
74
|
+
if (duplicated) {
|
|
75
|
+
this.logger.warn(`duplicate login was detected for principal: ${principal.id}`);
|
|
76
|
+
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.UNAUTHORIZED);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return principal;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.DefaultJwtStrategyProvider = DefaultJwtStrategyProvider;
|
|
83
|
+
class SimpleJwtStrategyProvider extends DefaultJwtStrategyProvider {
|
|
84
|
+
constructor(jwtOptions) {
|
|
85
|
+
super(jwtOptions, new auth_provider_1.SimpleAuthProvider());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.SimpleJwtStrategyProvider = SimpleJwtStrategyProvider;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Strategy } from "passport-jwt";
|
|
2
|
-
import { JwtStrategyProvider } from "./strategy-provider";
|
|
2
|
+
import { JwtStrategyProvider } from "./jwt-strategy-provider";
|
|
3
3
|
declare const JwtStrategy_base: new (...args: any[]) => Strategy;
|
|
4
4
|
export declare class JwtStrategy extends JwtStrategy_base {
|
|
5
5
|
private readonly strategyProvider;
|
|
@@ -13,8 +13,8 @@ exports.JwtStrategy = void 0;
|
|
|
13
13
|
const passport_jwt_1 = require("passport-jwt");
|
|
14
14
|
const passport_1 = require("@nestjs/passport");
|
|
15
15
|
const common_1 = require("@nestjs/common");
|
|
16
|
-
const strategy_provider_1 = require("./strategy-provider");
|
|
17
16
|
const constant_1 = require("../constant");
|
|
17
|
+
const jwt_strategy_provider_1 = require("./jwt-strategy-provider");
|
|
18
18
|
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, constant_1.JWT_STRATEGY_NAME) {
|
|
19
19
|
constructor(strategyProvider) {
|
|
20
20
|
super({
|
|
@@ -33,6 +33,6 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
33
33
|
};
|
|
34
34
|
JwtStrategy = __decorate([
|
|
35
35
|
(0, common_1.Injectable)(),
|
|
36
|
-
__metadata("design:paramtypes", [
|
|
36
|
+
__metadata("design:paramtypes", [jwt_strategy_provider_1.JwtStrategyProvider])
|
|
37
37
|
], JwtStrategy);
|
|
38
38
|
exports.JwtStrategy = JwtStrategy;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { JwtOptions as jOption } from "@nathapp/auth";
|
|
3
3
|
import { JwtFromRequestFunction } from "passport-jwt";
|
|
4
4
|
import { Request } from "express";
|
|
5
|
-
import {
|
|
5
|
+
import { IPrincipal } from "../auth-provider";
|
|
6
6
|
import * as jwt from 'jsonwebtoken';
|
|
7
7
|
export interface JwtNestJsOptions {
|
|
8
8
|
bindIp?: boolean;
|
|
@@ -18,25 +18,3 @@ export interface StrategyProvider {
|
|
|
18
18
|
sign(payload: string | object | Buffer): string;
|
|
19
19
|
verify(token: string, verifyOption?: jwt.VerifyOptions): object | string;
|
|
20
20
|
}
|
|
21
|
-
export declare abstract class JwtStrategyProvider implements StrategyProvider {
|
|
22
|
-
protected readonly jwtOptions: JwtOptions;
|
|
23
|
-
private readonly jwtProvider;
|
|
24
|
-
readonly secretOrPrivateKey: jwt.Secret;
|
|
25
|
-
readonly secretOrPublicKey: jwt.Secret;
|
|
26
|
-
readonly jwtFromRequestFunction: JwtFromRequestFunction;
|
|
27
|
-
readonly ignoreExpiration: boolean;
|
|
28
|
-
readonly passReqToCallback: boolean;
|
|
29
|
-
constructor(jwtOptions: JwtOptions);
|
|
30
|
-
sign(payload: string | object | Buffer): string;
|
|
31
|
-
verify(token: string, verifyOption?: jwt.VerifyOptions): string | object;
|
|
32
|
-
abstract validate(req: Request, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
33
|
-
}
|
|
34
|
-
export declare class DefaultJwtStrategyProvider extends JwtStrategyProvider {
|
|
35
|
-
private readonly authProvider;
|
|
36
|
-
private readonly logger;
|
|
37
|
-
constructor(jwtOptions: JwtOptions, authProvider: AuthProvider);
|
|
38
|
-
validate(req: Request, payload: any): Promise<IPrincipal>;
|
|
39
|
-
}
|
|
40
|
-
export declare class SimpleJwtStrategyProvider extends DefaultJwtStrategyProvider {
|
|
41
|
-
constructor(jwtOptions: JwtOptions);
|
|
42
|
-
}
|
|
@@ -1,82 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleJwtStrategyProvider = exports.DefaultJwtStrategyProvider = exports.JwtStrategyProvider = void 0;
|
|
4
|
-
const auth_1 = require("@nathapp/auth");
|
|
5
|
-
const passport_jwt_1 = require("passport-jwt");
|
|
6
|
-
const requestIp = require("request-ip");
|
|
7
|
-
const auth_provider_1 = require("../auth-provider");
|
|
8
|
-
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
9
|
-
const common_1 = require("@nestjs/common");
|
|
10
|
-
class JwtStrategyProvider {
|
|
11
|
-
constructor(jwtOptions) {
|
|
12
|
-
const extraOptions = {
|
|
13
|
-
bindIp: false,
|
|
14
|
-
allowDuplicateLogin: true,
|
|
15
|
-
checkBlacklisted: true,
|
|
16
|
-
ignoreExpiration: false,
|
|
17
|
-
passReqToCallback: true,
|
|
18
|
-
};
|
|
19
|
-
this.jwtOptions = Object.assign({}, extraOptions, jwtOptions);
|
|
20
|
-
this.jwtProvider = new auth_1.JwtProvider(jwtOptions);
|
|
21
|
-
this.secretOrPrivateKey = this.jwtProvider.secretOrPrivateKey;
|
|
22
|
-
this.secretOrPublicKey = this.jwtProvider.secretOrPublicKey;
|
|
23
|
-
this.jwtFromRequestFunction = this.jwtOptions.jwtFromRequestFunction || passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken();
|
|
24
|
-
this.ignoreExpiration = this.jwtOptions.ignoreExpiration;
|
|
25
|
-
this.passReqToCallback = this.jwtOptions.passReqToCallback;
|
|
26
|
-
}
|
|
27
|
-
sign(payload) {
|
|
28
|
-
return this.jwtProvider.sign(payload);
|
|
29
|
-
}
|
|
30
|
-
verify(token, verifyOption) {
|
|
31
|
-
return this.jwtProvider.verify(token, verifyOption);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.JwtStrategyProvider = JwtStrategyProvider;
|
|
35
|
-
class DefaultJwtStrategyProvider extends JwtStrategyProvider {
|
|
36
|
-
constructor(jwtOptions, authProvider) {
|
|
37
|
-
super(jwtOptions);
|
|
38
|
-
this.authProvider = authProvider;
|
|
39
|
-
this.logger = new common_1.Logger(DefaultJwtStrategyProvider.name);
|
|
40
|
-
}
|
|
41
|
-
async validate(req, payload) {
|
|
42
|
-
const { checkBlacklisted, bindIp, allowDuplicateLogin } = this.jwtOptions;
|
|
43
|
-
this.logger.debug(`validating Jwt request`);
|
|
44
|
-
this.logger.verbose(`payload: ${JSON.stringify(payload)}`);
|
|
45
|
-
const principal = await this.authProvider.getPrincipal(payload);
|
|
46
|
-
this.logger.verbose(`principal: ${JSON.stringify(principal)}`);
|
|
47
|
-
if (!principal) {
|
|
48
|
-
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.NOT_FOUND);
|
|
49
|
-
}
|
|
50
|
-
if (principal.revoked) {
|
|
51
|
-
this.logger.warn(`principal: ${principal.id} has revoked.`);
|
|
52
|
-
this.logger.debug(`principal: ${principal.id} has revoked. token: ${principal.hashToken}`);
|
|
53
|
-
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.UNAUTHORIZED);
|
|
54
|
-
}
|
|
55
|
-
if (checkBlacklisted && principal.blacklisted) {
|
|
56
|
-
this.logger.warn(`principal: ${principal.id} was blacklisted.`);
|
|
57
|
-
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.FORBIDDEN_BLACKLISTED);
|
|
58
|
-
}
|
|
59
|
-
if (bindIp) {
|
|
60
|
-
const reqIp = requestIp.getClientIp(req);
|
|
61
|
-
if (!principal.loginIP || principal.loginIP != reqIp) {
|
|
62
|
-
this.logger.debug(`principal: ${principal.id} is from different IP.`);
|
|
63
|
-
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.FORBIDDEN_IP_NOT_MATCH);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (!allowDuplicateLogin) {
|
|
67
|
-
const duplicated = await this.authProvider.isDuplicateLogin(principal, payload);
|
|
68
|
-
if (duplicated) {
|
|
69
|
-
this.logger.warn(`duplicate login was detected for principal: ${principal.id}`);
|
|
70
|
-
throw new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.UNAUTHORIZED);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return principal;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.DefaultJwtStrategyProvider = DefaultJwtStrategyProvider;
|
|
77
|
-
class SimpleJwtStrategyProvider extends DefaultJwtStrategyProvider {
|
|
78
|
-
constructor(jwtOptions) {
|
|
79
|
-
super(jwtOptions, new auth_provider_1.SimpleAuthProvider());
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.SimpleJwtStrategyProvider = SimpleJwtStrategyProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-auth",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.9",
|
|
4
4
|
"description": "nestjs-auth",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"lib": "lib"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nathapp/auth": "^1.0.1
|
|
36
|
-
"@nathapp/nestjs-common": "^1.0.1-rc.
|
|
35
|
+
"@nathapp/auth": "^1.0.1",
|
|
36
|
+
"@nathapp/nestjs-common": "^1.0.1-rc.7",
|
|
37
37
|
"passport-jwt": "^4.0.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|