@nathapp/nestjs-auth 1.0.0-rc.22 → 1.0.0-rc.24
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/README.md +2 -0
- package/dist/decorator/index.d.ts +2 -1
- package/dist/decorator/index.js +3 -1
- package/dist/decorator/principal.decorator.d.ts +1 -0
- package/dist/decorator/principal.decorator.js +12 -0
- package/dist/strategy/index.d.ts +2 -1
- package/dist/strategy/jwt-refresh-strategy-provider.d.ts +4 -4
- package/dist/strategy/jwt-strategy-provider.d.ts +4 -4
- package/dist/strategy/jwt-strategy-provider.js +1 -1
- package/dist/strategy/strategy-provider.d.ts +1 -15
- package/dist/strategy/type-interface.d.ts +14 -0
- package/dist/strategy/type-interface.js +2 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IS_PUBLIC_KEY, Public } from "./is-public.decorator";
|
|
2
2
|
import { PERMISSION_KEY, RequiredPermission } from "./permission.decorator";
|
|
3
|
+
import { Principal } from "./principal.decorator";
|
|
3
4
|
import { RefreshToken, REFRESH_TOKEN } from "./refresh-token.decorator";
|
|
4
|
-
export { IS_PUBLIC_KEY, Public, RequiredPermission, PERMISSION_KEY, RefreshToken, REFRESH_TOKEN, };
|
|
5
|
+
export { IS_PUBLIC_KEY, Public, RequiredPermission, PERMISSION_KEY, RefreshToken, REFRESH_TOKEN, Principal, };
|
package/dist/decorator/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REFRESH_TOKEN = exports.RefreshToken = exports.PERMISSION_KEY = exports.RequiredPermission = exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
3
|
+
exports.Principal = exports.REFRESH_TOKEN = exports.RefreshToken = exports.PERMISSION_KEY = exports.RequiredPermission = exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
4
|
const is_public_decorator_1 = require("./is-public.decorator");
|
|
5
5
|
Object.defineProperty(exports, "IS_PUBLIC_KEY", { enumerable: true, get: function () { return is_public_decorator_1.IS_PUBLIC_KEY; } });
|
|
6
6
|
Object.defineProperty(exports, "Public", { enumerable: true, get: function () { return is_public_decorator_1.Public; } });
|
|
7
7
|
const permission_decorator_1 = require("./permission.decorator");
|
|
8
8
|
Object.defineProperty(exports, "PERMISSION_KEY", { enumerable: true, get: function () { return permission_decorator_1.PERMISSION_KEY; } });
|
|
9
9
|
Object.defineProperty(exports, "RequiredPermission", { enumerable: true, get: function () { return permission_decorator_1.RequiredPermission; } });
|
|
10
|
+
const principal_decorator_1 = require("./principal.decorator");
|
|
11
|
+
Object.defineProperty(exports, "Principal", { enumerable: true, get: function () { return principal_decorator_1.Principal; } });
|
|
10
12
|
const refresh_token_decorator_1 = require("./refresh-token.decorator");
|
|
11
13
|
Object.defineProperty(exports, "RefreshToken", { enumerable: true, get: function () { return refresh_token_decorator_1.RefreshToken; } });
|
|
12
14
|
Object.defineProperty(exports, "REFRESH_TOKEN", { enumerable: true, get: function () { return refresh_token_decorator_1.REFRESH_TOKEN; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Principal: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Principal = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.Principal = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
const user = request.user;
|
|
8
|
+
if (data && data !== "") {
|
|
9
|
+
return user[data];
|
|
10
|
+
}
|
|
11
|
+
return user;
|
|
12
|
+
});
|
package/dist/strategy/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { JwtRefreshStrategy } from "./jwt-refresh-strategy";
|
|
|
2
2
|
import { DefaultJwtRefreshStrategyProvider, JwtRefreshStrategyProvider } from "./jwt-refresh-strategy-provider";
|
|
3
3
|
import { JwtStrategy } from "./jwt-strategy";
|
|
4
4
|
import { DefaultJwtStrategyProvider, JwtStrategyProvider, SimpleJwtStrategyProvider } from "./jwt-strategy-provider";
|
|
5
|
-
import { StrategyProvider,
|
|
5
|
+
import { StrategyProvider, IStrategyProvider } from "./strategy-provider";
|
|
6
|
+
import { JwtNestJsOptions, JwtOptions, Req, VerifyOptions } from "./type-interface";
|
|
6
7
|
export { Req, JwtOptions, JwtNestJsOptions, VerifyOptions, IStrategyProvider, StrategyProvider, JwtStrategyProvider, DefaultJwtStrategyProvider, SimpleJwtStrategyProvider, JwtRefreshStrategyProvider, DefaultJwtRefreshStrategyProvider, JwtStrategy, JwtRefreshStrategy, };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { StrategyProvider } from "./strategy-provider";
|
|
3
3
|
import * as jwt from 'jsonwebtoken';
|
|
4
4
|
import { JwtFromRequestFunction } from "passport-jwt";
|
|
5
5
|
import { IPrincipal } from "../auth-provider";
|
|
6
|
-
import {
|
|
6
|
+
import { JwtOptions, Req } from "./type-interface";
|
|
7
7
|
export declare abstract class JwtRefreshStrategyProvider implements StrategyProvider {
|
|
8
8
|
protected readonly jwtOptions: JwtOptions;
|
|
9
9
|
private readonly jwtProvider;
|
|
@@ -15,9 +15,9 @@ export declare abstract class JwtRefreshStrategyProvider implements StrategyProv
|
|
|
15
15
|
constructor(jwtOptions: JwtOptions);
|
|
16
16
|
sign(payload: string | object | Buffer): string;
|
|
17
17
|
verify(token: string, verifyOption?: jwt.VerifyOptions): string | object;
|
|
18
|
-
abstract validate(req:
|
|
18
|
+
abstract validate(req: Req, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
19
19
|
}
|
|
20
20
|
export declare class DefaultJwtRefreshStrategyProvider extends JwtRefreshStrategyProvider {
|
|
21
21
|
constructor(jwtOptions: JwtOptions);
|
|
22
|
-
validate(req:
|
|
22
|
+
validate(req: Req, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
23
23
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { JwtFromRequestFunction } from "passport-jwt";
|
|
3
3
|
import { IPrincipal, AuthProvider } from "../auth-provider";
|
|
4
|
-
import {
|
|
4
|
+
import { StrategyProvider } from "./strategy-provider";
|
|
5
5
|
import * as jwt from 'jsonwebtoken';
|
|
6
|
-
import {
|
|
6
|
+
import { JwtOptions, Req } from "./type-interface";
|
|
7
7
|
export declare abstract class JwtStrategyProvider implements StrategyProvider {
|
|
8
8
|
protected readonly jwtOptions: JwtOptions;
|
|
9
9
|
private readonly jwtProvider;
|
|
@@ -15,8 +15,8 @@ export declare abstract class JwtStrategyProvider implements StrategyProvider {
|
|
|
15
15
|
constructor(jwtOptions: JwtOptions);
|
|
16
16
|
sign(payload: string | object | Buffer): string;
|
|
17
17
|
verify(token: string, verifyOption?: jwt.VerifyOptions): string | object;
|
|
18
|
-
abstract validate(req:
|
|
19
|
-
abstract validate<T>(req:
|
|
18
|
+
abstract validate(req: Req, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
19
|
+
abstract validate<T>(req: Req, payload: any): T | Promise<T>;
|
|
20
20
|
}
|
|
21
21
|
export declare class DefaultJwtStrategyProvider extends JwtStrategyProvider {
|
|
22
22
|
private readonly authProvider;
|
|
@@ -59,7 +59,7 @@ class DefaultJwtStrategyProvider extends JwtStrategyProvider {
|
|
|
59
59
|
}
|
|
60
60
|
if (bindIp) {
|
|
61
61
|
if (!req && !passReqToCallback) {
|
|
62
|
-
this.logger.warn(`req is undefined,
|
|
62
|
+
this.logger.warn(`req is undefined, please set passReqToCallback to true, bindIp check is ignored`);
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
const reqIp = requestIp.getClientIp(req);
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { JwtOptions as jOption } from "@nathapp/auth";
|
|
3
|
-
import { JwtFromRequestFunction } from "passport-jwt";
|
|
4
|
-
import { Request } from "express";
|
|
5
2
|
import { IPrincipal } from "../auth-provider";
|
|
6
|
-
import
|
|
7
|
-
export interface JwtNestJsOptions {
|
|
8
|
-
bindIp?: boolean;
|
|
9
|
-
allowDuplicateLogin?: boolean;
|
|
10
|
-
checkBlacklisted?: boolean;
|
|
11
|
-
ignoreExpiration?: boolean;
|
|
12
|
-
passReqToCallback?: boolean;
|
|
13
|
-
jwtFromRequestFunction?: JwtFromRequestFunction;
|
|
14
|
-
}
|
|
15
|
-
export declare type JwtOptions = JwtNestJsOptions & jOption;
|
|
16
|
-
export declare type VerifyOptions = jwt.VerifyOptions;
|
|
17
|
-
export declare type Req = Request;
|
|
3
|
+
import { Req, VerifyOptions } from "./type-interface";
|
|
18
4
|
export interface IStrategyProvider {
|
|
19
5
|
validate(req: Req, payload: any): IPrincipal | Promise<IPrincipal>;
|
|
20
6
|
validate<T>(req: Req, payload: any): T | Promise<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
2
|
+
import { JwtOptions as jOption } from "@nathapp/auth";
|
|
3
|
+
import { JwtFromRequestFunction } from "passport-jwt";
|
|
4
|
+
export interface JwtNestJsOptions {
|
|
5
|
+
bindIp?: boolean;
|
|
6
|
+
allowDuplicateLogin?: boolean;
|
|
7
|
+
checkBlacklisted?: boolean;
|
|
8
|
+
ignoreExpiration?: boolean;
|
|
9
|
+
passReqToCallback?: boolean;
|
|
10
|
+
jwtFromRequestFunction?: JwtFromRequestFunction;
|
|
11
|
+
}
|
|
12
|
+
export declare type JwtOptions = JwtNestJsOptions & jOption;
|
|
13
|
+
export declare type VerifyOptions = jwt.VerifyOptions;
|
|
14
|
+
export declare type Req = any;
|
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.24",
|
|
4
4
|
"description": "nestjs-auth",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@golevelup/ts-jest": "^0.3.7",
|
|
17
|
-
"@nestjs/platform-express": "^
|
|
18
|
-
"@nestjs/platform-fastify": "^
|
|
19
|
-
"@nestjs/testing": "^
|
|
17
|
+
"@nestjs/platform-express": "^10.0.0",
|
|
18
|
+
"@nestjs/platform-fastify": "^10.0.0",
|
|
19
|
+
"@nestjs/testing": "^10.0.0",
|
|
20
20
|
"@types/jest": "^29.5.2",
|
|
21
21
|
"@types/node": "^17.0.45",
|
|
22
22
|
"@types/passport-jwt": "^3.0.8",
|
|
23
|
+
"@types/request-ip": "^0.0.39",
|
|
23
24
|
"@types/supertest": "^2.0.12",
|
|
24
25
|
"@typescript-eslint/eslint-plugin": "^4",
|
|
25
26
|
"@typescript-eslint/parser": "^4",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@nathapp/auth": "^1.0.1",
|
|
42
|
-
"@nathapp/nestjs-common": "^1.0.1-rc.
|
|
43
|
+
"@nathapp/nestjs-common": "^1.0.1-rc.20",
|
|
43
44
|
"passport-jwt": "^4.0.1"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|