win-portal-auth-sdk 1.4.0 → 1.5.0
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 +7 -6
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/index.js +3 -1
- package/dist/client/api/todo.api.d.ts +31 -0
- package/dist/client/api/todo.api.d.ts.map +1 -0
- package/dist/client/api/todo.api.js +36 -0
- package/dist/client/auth-client.d.ts +2 -1
- package/dist/client/auth-client.d.ts.map +1 -1
- package/dist/client/auth-client.js +1 -0
- package/dist/index.d.ts +1 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -11
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/todo.types.d.ts +162 -0
- package/dist/types/todo.types.d.ts.map +1 -0
- package/dist/types/todo.types.js +18 -0
- package/package.json +3 -41
- package/dist/nestjs/decorators/current-token.decorator.d.ts +0 -29
- package/dist/nestjs/decorators/current-token.decorator.d.ts.map +0 -1
- package/dist/nestjs/decorators/current-token.decorator.js +0 -36
- package/dist/nestjs/decorators/current-user.decorator.d.ts +0 -26
- package/dist/nestjs/decorators/current-user.decorator.d.ts.map +0 -1
- package/dist/nestjs/decorators/current-user.decorator.js +0 -33
- package/dist/nestjs/decorators/index.d.ts +0 -9
- package/dist/nestjs/decorators/index.d.ts.map +0 -1
- package/dist/nestjs/decorators/index.js +0 -15
- package/dist/nestjs/decorators/public.decorator.d.ts +0 -31
- package/dist/nestjs/decorators/public.decorator.d.ts.map +0 -1
- package/dist/nestjs/decorators/public.decorator.js +0 -36
- package/dist/nestjs/guards/index.d.ts +0 -7
- package/dist/nestjs/guards/index.d.ts.map +0 -1
- package/dist/nestjs/guards/index.js +0 -11
- package/dist/nestjs/guards/oauth-auth.guard.d.ts +0 -139
- package/dist/nestjs/guards/oauth-auth.guard.d.ts.map +0 -1
- package/dist/nestjs/guards/oauth-auth.guard.js +0 -257
- package/dist/nestjs/index.d.ts +0 -28
- package/dist/nestjs/index.d.ts.map +0 -1
- package/dist/nestjs/index.js +0 -47
- package/dist/nestjs/middleware/index.d.ts +0 -7
- package/dist/nestjs/middleware/index.d.ts.map +0 -1
- package/dist/nestjs/middleware/index.js +0 -11
- package/dist/nestjs/middleware/request-context.middleware.d.ts +0 -62
- package/dist/nestjs/middleware/request-context.middleware.d.ts.map +0 -1
- package/dist/nestjs/middleware/request-context.middleware.js +0 -122
- package/dist/nestjs/types/request-context.types.d.ts +0 -69
- package/dist/nestjs/types/request-context.types.d.ts.map +0 -1
- package/dist/nestjs/types/request-context.types.js +0 -33
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nestjs/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* NestJS Decorators
|
|
4
|
-
*
|
|
5
|
-
* Decorators for NestJS applications using win-portal-auth-sdk
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.IS_PUBLIC_KEY = exports.Public = exports.CurrentToken = exports.CurrentUser = void 0;
|
|
9
|
-
var current_user_decorator_1 = require("./current-user.decorator");
|
|
10
|
-
Object.defineProperty(exports, "CurrentUser", { enumerable: true, get: function () { return current_user_decorator_1.CurrentUser; } });
|
|
11
|
-
var current_token_decorator_1 = require("./current-token.decorator");
|
|
12
|
-
Object.defineProperty(exports, "CurrentToken", { enumerable: true, get: function () { return current_token_decorator_1.CurrentToken; } });
|
|
13
|
-
var public_decorator_1 = require("./public.decorator");
|
|
14
|
-
Object.defineProperty(exports, "Public", { enumerable: true, get: function () { return public_decorator_1.Public; } });
|
|
15
|
-
Object.defineProperty(exports, "IS_PUBLIC_KEY", { enumerable: true, get: function () { return public_decorator_1.IS_PUBLIC_KEY; } });
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public Decorator
|
|
3
|
-
*
|
|
4
|
-
* Decorator to mark endpoints as public (skip authentication)
|
|
5
|
-
* Used with guards that support the IS_PUBLIC_KEY metadata.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Metadata key for public endpoints
|
|
9
|
-
*/
|
|
10
|
-
export declare const IS_PUBLIC_KEY = "isPublic";
|
|
11
|
-
/**
|
|
12
|
-
* Public decorator factory
|
|
13
|
-
*
|
|
14
|
-
* Marks an endpoint or controller as public, allowing access without authentication.
|
|
15
|
-
* Guards that support this decorator will skip authentication checks.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* @Controller('api')
|
|
20
|
-
* @UseGuards(OAuthAuthGuard)
|
|
21
|
-
* export class ApiController {
|
|
22
|
-
* @Public()
|
|
23
|
-
* @Get('health')
|
|
24
|
-
* healthCheck() {
|
|
25
|
-
* return { status: 'ok' };
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare const Public: () => any;
|
|
31
|
-
//# sourceMappingURL=public.decorator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public.decorator.d.ts","sourceRoot":"","sources":["../../../src/nestjs/decorators/public.decorator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,aAAa,CAAC;AAKxC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,MAAM,WAAyC,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Public Decorator
|
|
4
|
-
*
|
|
5
|
-
* Decorator to mark endpoints as public (skip authentication)
|
|
6
|
-
* Used with guards that support the IS_PUBLIC_KEY metadata.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
10
|
-
/**
|
|
11
|
-
* Metadata key for public endpoints
|
|
12
|
-
*/
|
|
13
|
-
exports.IS_PUBLIC_KEY = 'isPublic';
|
|
14
|
-
// @ts-expect-error - @nestjs/common is a peer dependency, will be available at runtime in NestJS apps
|
|
15
|
-
const common_1 = require("@nestjs/common");
|
|
16
|
-
/**
|
|
17
|
-
* Public decorator factory
|
|
18
|
-
*
|
|
19
|
-
* Marks an endpoint or controller as public, allowing access without authentication.
|
|
20
|
-
* Guards that support this decorator will skip authentication checks.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* @Controller('api')
|
|
25
|
-
* @UseGuards(OAuthAuthGuard)
|
|
26
|
-
* export class ApiController {
|
|
27
|
-
* @Public()
|
|
28
|
-
* @Get('health')
|
|
29
|
-
* healthCheck() {
|
|
30
|
-
* return { status: 'ok' };
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
36
|
-
exports.Public = Public;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nestjs/guards/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* NestJS Guards
|
|
4
|
-
*
|
|
5
|
-
* Guards for NestJS applications using win-portal-auth-sdk
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.createOAuthAuthGuard = exports.OAuthAuthGuard = void 0;
|
|
9
|
-
var oauth_auth_guard_1 = require("./oauth-auth.guard");
|
|
10
|
-
Object.defineProperty(exports, "OAuthAuthGuard", { enumerable: true, get: function () { return oauth_auth_guard_1.OAuthAuthGuard; } });
|
|
11
|
-
Object.defineProperty(exports, "createOAuthAuthGuard", { enumerable: true, get: function () { return oauth_auth_guard_1.createOAuthAuthGuard; } });
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth Auth Guard
|
|
3
|
-
*
|
|
4
|
-
* Extended guard with OAuth-first validation, Public decorator support,
|
|
5
|
-
* and optional RequestContextService integration.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - OAuth-first validation: Tries OAuth token validation first, falls back to JWT
|
|
9
|
-
* - Public decorator support: Skips authentication for endpoints marked with @Public()
|
|
10
|
-
* - Optional RequestContextService integration: Sets user context if service is available
|
|
11
|
-
*
|
|
12
|
-
* @note This guard requires @nestjs/common and @nestjs/core as peer dependencies.
|
|
13
|
-
* The guard uses dynamic imports to avoid requiring NestJS as a direct dependency.
|
|
14
|
-
*/
|
|
15
|
-
import { AuthClient } from '../../client';
|
|
16
|
-
import { User } from '../../types';
|
|
17
|
-
import { MiddlewareConfig } from '../../middleware/types';
|
|
18
|
-
/**
|
|
19
|
-
* Configuration for OAuthAuthGuard
|
|
20
|
-
*/
|
|
21
|
-
export interface OAuthAuthGuardConfig extends Omit<MiddlewareConfig, 'optional'> {
|
|
22
|
-
/**
|
|
23
|
-
* AuthClient instance (injected via DI)
|
|
24
|
-
* If not provided, guard will create its own instance
|
|
25
|
-
*/
|
|
26
|
-
authClient?: AuthClient;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* OAuth Auth Guard Class
|
|
30
|
-
*
|
|
31
|
-
* This guard extends the base SDK guard and adds:
|
|
32
|
-
* - Public decorator support
|
|
33
|
-
* - OAuth-first token validation
|
|
34
|
-
* - Optional RequestContextService integration
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* // In your module
|
|
39
|
-
* @Module({
|
|
40
|
-
* providers: [
|
|
41
|
-
* {
|
|
42
|
-
* provide: 'AUTH_CLIENT',
|
|
43
|
-
* useFactory: () => new AuthClient({
|
|
44
|
-
* baseURL: process.env.AUTH_API_URL,
|
|
45
|
-
* apiKey: process.env.AUTH_API_KEY,
|
|
46
|
-
* }),
|
|
47
|
-
* },
|
|
48
|
-
* ],
|
|
49
|
-
* })
|
|
50
|
-
* export class AuthModule {}
|
|
51
|
-
*
|
|
52
|
-
* // In your controller
|
|
53
|
-
* @Controller('api')
|
|
54
|
-
* @UseGuards(OAuthAuthGuard)
|
|
55
|
-
* export class ApiController {
|
|
56
|
-
* @Get('profile')
|
|
57
|
-
* getProfile(@CurrentUser() user: User) {
|
|
58
|
-
* return user;
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
* @Public()
|
|
62
|
-
* @Get('health')
|
|
63
|
-
* healthCheck() {
|
|
64
|
-
* return { status: 'ok' };
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
export declare class OAuthAuthGuard {
|
|
70
|
-
readonly baseGuard: any;
|
|
71
|
-
readonly authClient?: AuthClient;
|
|
72
|
-
readonly reflector: any;
|
|
73
|
-
readonly logger: any;
|
|
74
|
-
constructor(config: OAuthAuthGuardConfig, reflector: any, authClient?: AuthClient);
|
|
75
|
-
canActivate(context: any): Promise<boolean>;
|
|
76
|
-
/**
|
|
77
|
-
* Set user info in RequestContextService if available
|
|
78
|
-
* @internal
|
|
79
|
-
*/
|
|
80
|
-
setRequestContext(user: User, token: string): void;
|
|
81
|
-
/**
|
|
82
|
-
* Handle successful authentication
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
handleSuccess(request: any, token: string | null): boolean;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Factory function to create OAuthAuthGuard
|
|
89
|
-
*
|
|
90
|
-
* This factory creates a guard class that can be used with NestJS dependency injection.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* // In your module
|
|
95
|
-
* @Module({
|
|
96
|
-
* providers: [
|
|
97
|
-
* {
|
|
98
|
-
* provide: 'AUTH_CLIENT',
|
|
99
|
-
* useFactory: () => new AuthClient({
|
|
100
|
-
* baseURL: process.env.AUTH_API_URL,
|
|
101
|
-
* apiKey: process.env.AUTH_API_KEY,
|
|
102
|
-
* }),
|
|
103
|
-
* },
|
|
104
|
-
* ],
|
|
105
|
-
* })
|
|
106
|
-
* export class AuthModule {}
|
|
107
|
-
*
|
|
108
|
-
* // Create guard instance
|
|
109
|
-
* const guard = createOAuthAuthGuard({
|
|
110
|
-
* baseURL: process.env.AUTH_API_URL || '',
|
|
111
|
-
* apiKey: process.env.AUTH_API_KEY || '',
|
|
112
|
-
* });
|
|
113
|
-
*
|
|
114
|
-
* // Use in controller
|
|
115
|
-
* @Controller('api')
|
|
116
|
-
* @UseGuards(guard)
|
|
117
|
-
* export class ApiController {}
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export declare function createOAuthAuthGuard(config: OAuthAuthGuardConfig): {
|
|
121
|
-
new (reflector: any, authClient?: AuthClient): {
|
|
122
|
-
readonly baseGuard: any;
|
|
123
|
-
readonly authClient?: AuthClient | undefined;
|
|
124
|
-
readonly reflector: any;
|
|
125
|
-
readonly logger: any;
|
|
126
|
-
canActivate(context: any): Promise<boolean>;
|
|
127
|
-
/**
|
|
128
|
-
* Set user info in RequestContextService if available
|
|
129
|
-
* @internal
|
|
130
|
-
*/
|
|
131
|
-
setRequestContext(user: User, token: string): void;
|
|
132
|
-
/**
|
|
133
|
-
* Handle successful authentication
|
|
134
|
-
* @internal
|
|
135
|
-
*/
|
|
136
|
-
handleSuccess(request: any, token: string | null): boolean;
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
//# sourceMappingURL=oauth-auth.guard.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-auth.guard.d.ts","sourceRoot":"","sources":["../../../src/nestjs/guards/oauth-auth.guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC;IAC9E;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAAa,cAAc;IAGzB,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC;gBAGnB,MAAM,EAAE,oBAAoB,EAC5B,SAAS,EAAE,GAAG,EACd,UAAU,CAAC,EAAE,UAAU;IAgCnB,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAyGjD;;;OAGG;IACH,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAmBlD;;;OAGG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;CAM3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB;oBAEtC,GAAG,eAAe,UAAU;;;;;;QAtErD;;;WAGG;;QAoBH;;;WAGG;;;EAiDJ"}
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* OAuth Auth Guard
|
|
4
|
-
*
|
|
5
|
-
* Extended guard with OAuth-first validation, Public decorator support,
|
|
6
|
-
* and optional RequestContextService integration.
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - OAuth-first validation: Tries OAuth token validation first, falls back to JWT
|
|
10
|
-
* - Public decorator support: Skips authentication for endpoints marked with @Public()
|
|
11
|
-
* - Optional RequestContextService integration: Sets user context if service is available
|
|
12
|
-
*
|
|
13
|
-
* @note This guard requires @nestjs/common and @nestjs/core as peer dependencies.
|
|
14
|
-
* The guard uses dynamic imports to avoid requiring NestJS as a direct dependency.
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createOAuthAuthGuard = exports.OAuthAuthGuard = void 0;
|
|
18
|
-
const decorators_1 = require("../decorators");
|
|
19
|
-
const middleware_1 = require("../../middleware");
|
|
20
|
-
const request_context_types_1 = require("../types/request-context.types");
|
|
21
|
-
/**
|
|
22
|
-
* Base Auth Guard from SDK
|
|
23
|
-
* This is the foundation guard that handles JWT validation
|
|
24
|
-
*/
|
|
25
|
-
function createBaseAuthGuard(config) {
|
|
26
|
-
return (0, middleware_1.createAuthGuard)(config);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* OAuth Auth Guard Class
|
|
30
|
-
*
|
|
31
|
-
* This guard extends the base SDK guard and adds:
|
|
32
|
-
* - Public decorator support
|
|
33
|
-
* - OAuth-first token validation
|
|
34
|
-
* - Optional RequestContextService integration
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* // In your module
|
|
39
|
-
* @Module({
|
|
40
|
-
* providers: [
|
|
41
|
-
* {
|
|
42
|
-
* provide: 'AUTH_CLIENT',
|
|
43
|
-
* useFactory: () => new AuthClient({
|
|
44
|
-
* baseURL: process.env.AUTH_API_URL,
|
|
45
|
-
* apiKey: process.env.AUTH_API_KEY,
|
|
46
|
-
* }),
|
|
47
|
-
* },
|
|
48
|
-
* ],
|
|
49
|
-
* })
|
|
50
|
-
* export class AuthModule {}
|
|
51
|
-
*
|
|
52
|
-
* // In your controller
|
|
53
|
-
* @Controller('api')
|
|
54
|
-
* @UseGuards(OAuthAuthGuard)
|
|
55
|
-
* export class ApiController {
|
|
56
|
-
* @Get('profile')
|
|
57
|
-
* getProfile(@CurrentUser() user: User) {
|
|
58
|
-
* return user;
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
* @Public()
|
|
62
|
-
* @Get('health')
|
|
63
|
-
* healthCheck() {
|
|
64
|
-
* return { status: 'ok' };
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
class OAuthAuthGuard {
|
|
70
|
-
constructor(config, reflector, authClient) {
|
|
71
|
-
// Create base guard for fallback JWT validation
|
|
72
|
-
this.baseGuard = createBaseAuthGuard({
|
|
73
|
-
baseURL: config.baseURL,
|
|
74
|
-
apiKey: config.apiKey,
|
|
75
|
-
apiKeyHeader: config.apiKeyHeader || 'X-API-Key',
|
|
76
|
-
tokenStrategy: config.tokenStrategy || 'bearer',
|
|
77
|
-
cacheTimeout: config.cacheTimeout || 300,
|
|
78
|
-
});
|
|
79
|
-
this.authClient = authClient || config.authClient;
|
|
80
|
-
this.reflector = reflector;
|
|
81
|
-
// Try to get Logger from @nestjs/common
|
|
82
|
-
// Use dynamic require to avoid requiring @nestjs/common as direct dependency
|
|
83
|
-
try {
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
85
|
-
const { Logger } = require('@nestjs/common');
|
|
86
|
-
this.logger = new Logger('OAuthAuthGuard');
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
// Fallback logger if @nestjs/common is not available
|
|
90
|
-
// This should not happen in normal NestJS usage
|
|
91
|
-
this.logger = {
|
|
92
|
-
debug: () => { },
|
|
93
|
-
log: () => { },
|
|
94
|
-
warn: () => { },
|
|
95
|
-
error: () => { },
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async canActivate(context) {
|
|
100
|
-
// Check if endpoint is marked as public
|
|
101
|
-
const isPublic = this.reflector?.getAllAndOverride
|
|
102
|
-
? this.reflector.getAllAndOverride(decorators_1.IS_PUBLIC_KEY, [context.getHandler(), context.getClass()])
|
|
103
|
-
: undefined;
|
|
104
|
-
if (isPublic) {
|
|
105
|
-
this.logger.debug('Public endpoint - skipping authentication');
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
const request = context.switchToHttp().getRequest();
|
|
109
|
-
const authHeader = request.headers?.authorization;
|
|
110
|
-
if (!authHeader) {
|
|
111
|
-
// Try base guard (might handle missing token differently)
|
|
112
|
-
const result = await this.baseGuard.canActivate(context);
|
|
113
|
-
if (!result) {
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
115
|
-
const { UnauthorizedException } = require('@nestjs/common');
|
|
116
|
-
throw new UnauthorizedException('Missing authorization token');
|
|
117
|
-
}
|
|
118
|
-
return this.handleSuccess(request, request.token);
|
|
119
|
-
}
|
|
120
|
-
// Extract token from Authorization header
|
|
121
|
-
const token = authHeader.replace(/^Bearer\s+/i, '');
|
|
122
|
-
if (!token) {
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
124
|
-
const { UnauthorizedException } = require('@nestjs/common');
|
|
125
|
-
throw new UnauthorizedException('Missing authorization token');
|
|
126
|
-
}
|
|
127
|
-
// Check environment variables
|
|
128
|
-
const authApiUrl = process.env.AUTH_API_URL;
|
|
129
|
-
const authApiKey = process.env.AUTH_API_KEY;
|
|
130
|
-
if (!authApiUrl || !authApiKey) {
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
132
|
-
const { UnauthorizedException } = require('@nestjs/common');
|
|
133
|
-
throw new UnauthorizedException('Authentication service not configured');
|
|
134
|
-
}
|
|
135
|
-
try {
|
|
136
|
-
// Try OAuth validation first if AuthClient is available
|
|
137
|
-
if (this.authClient) {
|
|
138
|
-
try {
|
|
139
|
-
this.authClient.setToken(token, 'oauth');
|
|
140
|
-
const user = await this.authClient.auth.profile();
|
|
141
|
-
// Set user and token in request
|
|
142
|
-
request.user = user;
|
|
143
|
-
request.token = token;
|
|
144
|
-
// Set user info in RequestContextService (if available)
|
|
145
|
-
this.setRequestContext(user, token);
|
|
146
|
-
this.logger.debug(`OAuth authentication successful for user: ${user.id}`);
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
catch (oauthError) {
|
|
150
|
-
// OAuth validation failed, try base guard (JWT fallback)
|
|
151
|
-
this.logger.debug('OAuth validation failed, trying JWT fallback');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Fallback to base guard (JWT validation)
|
|
155
|
-
const result = await this.baseGuard.canActivate(context);
|
|
156
|
-
if (result === false) {
|
|
157
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
158
|
-
const { UnauthorizedException } = require('@nestjs/common');
|
|
159
|
-
throw new UnauthorizedException('Invalid or expired token');
|
|
160
|
-
}
|
|
161
|
-
// Set user info in RequestContextService (if available)
|
|
162
|
-
if (request.user) {
|
|
163
|
-
this.setRequestContext(request.user, token);
|
|
164
|
-
}
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
169
|
-
const { UnauthorizedException, HttpException } = require('@nestjs/common');
|
|
170
|
-
if (error instanceof UnauthorizedException) {
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
if (error instanceof HttpException) {
|
|
174
|
-
const httpError = error;
|
|
175
|
-
const status = httpError.getStatus();
|
|
176
|
-
if (status === 401 || status === 403) {
|
|
177
|
-
throw new UnauthorizedException('Invalid or expired token');
|
|
178
|
-
}
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
throw new UnauthorizedException('Invalid or expired token');
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Set user info in RequestContextService if available
|
|
186
|
-
* @internal
|
|
187
|
-
*/
|
|
188
|
-
setRequestContext(user, token) {
|
|
189
|
-
const requestContextService = (0, request_context_types_1.getRequestContextService)();
|
|
190
|
-
if (requestContextService) {
|
|
191
|
-
try {
|
|
192
|
-
requestContextService.setUserInfo(user.id, user.email, undefined, token);
|
|
193
|
-
if (user.permissions) {
|
|
194
|
-
requestContextService.setUserPermissions(user.permissions, user.roles || []);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
// RequestContextService not available or error setting context
|
|
199
|
-
// This is fine - guard will work without it
|
|
200
|
-
this.logger.debug('RequestContextService not available or error setting context');
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Handle successful authentication
|
|
206
|
-
* @internal
|
|
207
|
-
*/
|
|
208
|
-
handleSuccess(request, token) {
|
|
209
|
-
if (request.user && token) {
|
|
210
|
-
this.setRequestContext(request.user, token);
|
|
211
|
-
}
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
exports.OAuthAuthGuard = OAuthAuthGuard;
|
|
216
|
-
/**
|
|
217
|
-
* Factory function to create OAuthAuthGuard
|
|
218
|
-
*
|
|
219
|
-
* This factory creates a guard class that can be used with NestJS dependency injection.
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* // In your module
|
|
224
|
-
* @Module({
|
|
225
|
-
* providers: [
|
|
226
|
-
* {
|
|
227
|
-
* provide: 'AUTH_CLIENT',
|
|
228
|
-
* useFactory: () => new AuthClient({
|
|
229
|
-
* baseURL: process.env.AUTH_API_URL,
|
|
230
|
-
* apiKey: process.env.AUTH_API_KEY,
|
|
231
|
-
* }),
|
|
232
|
-
* },
|
|
233
|
-
* ],
|
|
234
|
-
* })
|
|
235
|
-
* export class AuthModule {}
|
|
236
|
-
*
|
|
237
|
-
* // Create guard instance
|
|
238
|
-
* const guard = createOAuthAuthGuard({
|
|
239
|
-
* baseURL: process.env.AUTH_API_URL || '',
|
|
240
|
-
* apiKey: process.env.AUTH_API_KEY || '',
|
|
241
|
-
* });
|
|
242
|
-
*
|
|
243
|
-
* // Use in controller
|
|
244
|
-
* @Controller('api')
|
|
245
|
-
* @UseGuards(guard)
|
|
246
|
-
* export class ApiController {}
|
|
247
|
-
* ```
|
|
248
|
-
*/
|
|
249
|
-
function createOAuthAuthGuard(config) {
|
|
250
|
-
class OAuthAuthGuardInstance extends OAuthAuthGuard {
|
|
251
|
-
constructor(reflector, authClient) {
|
|
252
|
-
super(config, reflector, authClient);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return OAuthAuthGuardInstance;
|
|
256
|
-
}
|
|
257
|
-
exports.createOAuthAuthGuard = createOAuthAuthGuard;
|
package/dist/nestjs/index.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NestJS Integration Module
|
|
3
|
-
*
|
|
4
|
-
* Complete NestJS integration for win-portal-auth-sdk
|
|
5
|
-
* Includes guards, decorators, and middleware for easy setup.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Import everything you need
|
|
10
|
-
* import {
|
|
11
|
-
* OAuthAuthGuard,
|
|
12
|
-
* createOAuthAuthGuard,
|
|
13
|
-
* CurrentUser,
|
|
14
|
-
* CurrentToken,
|
|
15
|
-
* Public,
|
|
16
|
-
* RequestContextMiddleware,
|
|
17
|
-
* } from 'win-portal-auth-sdk/nestjs';
|
|
18
|
-
*
|
|
19
|
-
* // Or import from specific modules
|
|
20
|
-
* import { OAuthAuthGuard } from 'win-portal-auth-sdk/nestjs/guards';
|
|
21
|
-
* import { CurrentUser, Public } from 'win-portal-auth-sdk/nestjs/decorators';
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export * from './guards';
|
|
25
|
-
export * from './decorators';
|
|
26
|
-
export * from './middleware';
|
|
27
|
-
export * from './types/request-context.types';
|
|
28
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nestjs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,cAAc,UAAU,CAAC;AAGzB,cAAc,cAAc,CAAC;AAG7B,cAAc,cAAc,CAAC;AAG7B,cAAc,+BAA+B,CAAC"}
|
package/dist/nestjs/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* NestJS Integration Module
|
|
4
|
-
*
|
|
5
|
-
* Complete NestJS integration for win-portal-auth-sdk
|
|
6
|
-
* Includes guards, decorators, and middleware for easy setup.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* // Import everything you need
|
|
11
|
-
* import {
|
|
12
|
-
* OAuthAuthGuard,
|
|
13
|
-
* createOAuthAuthGuard,
|
|
14
|
-
* CurrentUser,
|
|
15
|
-
* CurrentToken,
|
|
16
|
-
* Public,
|
|
17
|
-
* RequestContextMiddleware,
|
|
18
|
-
* } from 'win-portal-auth-sdk/nestjs';
|
|
19
|
-
*
|
|
20
|
-
* // Or import from specific modules
|
|
21
|
-
* import { OAuthAuthGuard } from 'win-portal-auth-sdk/nestjs/guards';
|
|
22
|
-
* import { CurrentUser, Public } from 'win-portal-auth-sdk/nestjs/decorators';
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
26
|
-
if (k2 === undefined) k2 = k;
|
|
27
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
28
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
29
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
30
|
-
}
|
|
31
|
-
Object.defineProperty(o, k2, desc);
|
|
32
|
-
}) : (function(o, m, k, k2) {
|
|
33
|
-
if (k2 === undefined) k2 = k;
|
|
34
|
-
o[k2] = m[k];
|
|
35
|
-
}));
|
|
36
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
37
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
// Guards
|
|
41
|
-
__exportStar(require("./guards"), exports);
|
|
42
|
-
// Decorators
|
|
43
|
-
__exportStar(require("./decorators"), exports);
|
|
44
|
-
// Middleware
|
|
45
|
-
__exportStar(require("./middleware"), exports);
|
|
46
|
-
// Types
|
|
47
|
-
__exportStar(require("./types/request-context.types"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nestjs/middleware/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* NestJS Middleware
|
|
4
|
-
*
|
|
5
|
-
* Middleware for NestJS applications using win-portal-auth-sdk
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.createRequestContextMiddleware = exports.RequestContextMiddleware = void 0;
|
|
9
|
-
var request_context_middleware_1 = require("./request-context.middleware");
|
|
10
|
-
Object.defineProperty(exports, "RequestContextMiddleware", { enumerable: true, get: function () { return request_context_middleware_1.RequestContextMiddleware; } });
|
|
11
|
-
Object.defineProperty(exports, "createRequestContextMiddleware", { enumerable: true, get: function () { return request_context_middleware_1.createRequestContextMiddleware; } });
|