@pawells/nestjs-auth 1.0.0-dev.4c8c698
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/LICENSE +21 -0
- package/README.md +602 -0
- package/build/LICENSE +21 -0
- package/build/README.md +602 -0
- package/build/admin/client/client.d.ts +82 -0
- package/build/admin/client/client.d.ts.map +1 -0
- package/build/admin/client/client.js +157 -0
- package/build/admin/client/client.js.map +1 -0
- package/build/admin/client/errors/base-error.d.ts +58 -0
- package/build/admin/client/errors/base-error.d.ts.map +1 -0
- package/build/admin/client/errors/base-error.js +100 -0
- package/build/admin/client/errors/base-error.js.map +1 -0
- package/build/admin/client/errors/index.d.ts +2 -0
- package/build/admin/client/errors/index.d.ts.map +1 -0
- package/build/admin/client/errors/index.js +2 -0
- package/build/admin/client/errors/index.js.map +1 -0
- package/build/admin/client/index.d.ts +6 -0
- package/build/admin/client/index.d.ts.map +1 -0
- package/build/admin/client/index.js +11 -0
- package/build/admin/client/index.js.map +1 -0
- package/build/admin/client/services/authentication.service.d.ts +54 -0
- package/build/admin/client/services/authentication.service.d.ts.map +1 -0
- package/build/admin/client/services/authentication.service.js +99 -0
- package/build/admin/client/services/authentication.service.js.map +1 -0
- package/build/admin/client/services/base-service.d.ts +39 -0
- package/build/admin/client/services/base-service.d.ts.map +1 -0
- package/build/admin/client/services/base-service.js +107 -0
- package/build/admin/client/services/base-service.js.map +1 -0
- package/build/admin/client/services/client.service.d.ts +86 -0
- package/build/admin/client/services/client.service.d.ts.map +1 -0
- package/build/admin/client/services/client.service.js +193 -0
- package/build/admin/client/services/client.service.js.map +1 -0
- package/build/admin/client/services/event.service.d.ts +84 -0
- package/build/admin/client/services/event.service.d.ts.map +1 -0
- package/build/admin/client/services/event.service.js +155 -0
- package/build/admin/client/services/event.service.js.map +1 -0
- package/build/admin/client/services/federated-identity.service.d.ts +89 -0
- package/build/admin/client/services/federated-identity.service.d.ts.map +1 -0
- package/build/admin/client/services/federated-identity.service.js +120 -0
- package/build/admin/client/services/federated-identity.service.js.map +1 -0
- package/build/admin/client/services/group.service.d.ts +52 -0
- package/build/admin/client/services/group.service.d.ts.map +1 -0
- package/build/admin/client/services/group.service.js +105 -0
- package/build/admin/client/services/group.service.js.map +1 -0
- package/build/admin/client/services/identity-provider.service.d.ts +47 -0
- package/build/admin/client/services/identity-provider.service.d.ts.map +1 -0
- package/build/admin/client/services/identity-provider.service.js +86 -0
- package/build/admin/client/services/identity-provider.service.js.map +1 -0
- package/build/admin/client/services/index.d.ts +11 -0
- package/build/admin/client/services/index.d.ts.map +1 -0
- package/build/admin/client/services/index.js +11 -0
- package/build/admin/client/services/index.js.map +1 -0
- package/build/admin/client/services/realm.service.d.ts +41 -0
- package/build/admin/client/services/realm.service.d.ts.map +1 -0
- package/build/admin/client/services/realm.service.js +80 -0
- package/build/admin/client/services/realm.service.js.map +1 -0
- package/build/admin/client/services/role.service.d.ts +45 -0
- package/build/admin/client/services/role.service.d.ts.map +1 -0
- package/build/admin/client/services/role.service.js +92 -0
- package/build/admin/client/services/role.service.js.map +1 -0
- package/build/admin/client/services/user.service.d.ts +84 -0
- package/build/admin/client/services/user.service.d.ts.map +1 -0
- package/build/admin/client/services/user.service.js +216 -0
- package/build/admin/client/services/user.service.js.map +1 -0
- package/build/admin/client/types/config.types.d.ts +59 -0
- package/build/admin/client/types/config.types.d.ts.map +1 -0
- package/build/admin/client/types/config.types.js +13 -0
- package/build/admin/client/types/config.types.js.map +1 -0
- package/build/admin/client/types/event.types.d.ts +176 -0
- package/build/admin/client/types/event.types.d.ts.map +1 -0
- package/build/admin/client/types/event.types.js +2 -0
- package/build/admin/client/types/event.types.js.map +1 -0
- package/build/admin/client/types/index.d.ts +4 -0
- package/build/admin/client/types/index.d.ts.map +1 -0
- package/build/admin/client/types/index.js +4 -0
- package/build/admin/client/types/index.js.map +1 -0
- package/build/admin/client/types/keycloak.types.d.ts +169 -0
- package/build/admin/client/types/keycloak.types.d.ts.map +1 -0
- package/build/admin/client/types/keycloak.types.js +2 -0
- package/build/admin/client/types/keycloak.types.js.map +1 -0
- package/build/admin/client/utils/index.d.ts +2 -0
- package/build/admin/client/utils/index.d.ts.map +1 -0
- package/build/admin/client/utils/index.js +2 -0
- package/build/admin/client/utils/index.js.map +1 -0
- package/build/admin/client/utils/retry.d.ts +40 -0
- package/build/admin/client/utils/retry.d.ts.map +1 -0
- package/build/admin/client/utils/retry.js +72 -0
- package/build/admin/client/utils/retry.js.map +1 -0
- package/build/admin/config/keycloak.config.d.ts +33 -0
- package/build/admin/config/keycloak.config.d.ts.map +1 -0
- package/build/admin/config/keycloak.config.js +2 -0
- package/build/admin/config/keycloak.config.js.map +1 -0
- package/build/admin/config/keycloak.defaults.d.ts +11 -0
- package/build/admin/config/keycloak.defaults.d.ts.map +1 -0
- package/build/admin/config/keycloak.defaults.js +60 -0
- package/build/admin/config/keycloak.defaults.js.map +1 -0
- package/build/admin/health/keycloak.health.d.ts +13 -0
- package/build/admin/health/keycloak.health.d.ts.map +1 -0
- package/build/admin/health/keycloak.health.js +54 -0
- package/build/admin/health/keycloak.health.js.map +1 -0
- package/build/admin/index.d.ts +10 -0
- package/build/admin/index.d.ts.map +1 -0
- package/build/admin/index.js +9 -0
- package/build/admin/index.js.map +1 -0
- package/build/admin/keycloak-admin.interfaces.d.ts +45 -0
- package/build/admin/keycloak-admin.interfaces.d.ts.map +1 -0
- package/build/admin/keycloak-admin.interfaces.js +2 -0
- package/build/admin/keycloak-admin.interfaces.js.map +1 -0
- package/build/admin/keycloak-admin.module.d.ts +23 -0
- package/build/admin/keycloak-admin.module.d.ts.map +1 -0
- package/build/admin/keycloak-admin.module.js +101 -0
- package/build/admin/keycloak-admin.module.js.map +1 -0
- package/build/admin/keycloak.constants.d.ts +16 -0
- package/build/admin/keycloak.constants.d.ts.map +1 -0
- package/build/admin/keycloak.constants.js +16 -0
- package/build/admin/keycloak.constants.js.map +1 -0
- package/build/admin/permissions/index.d.ts +2 -0
- package/build/admin/permissions/index.d.ts.map +1 -0
- package/build/admin/permissions/index.js +2 -0
- package/build/admin/permissions/index.js.map +1 -0
- package/build/admin/permissions/keycloak-admin.permissions.d.ts +45 -0
- package/build/admin/permissions/keycloak-admin.permissions.d.ts.map +1 -0
- package/build/admin/permissions/keycloak-admin.permissions.js +68 -0
- package/build/admin/permissions/keycloak-admin.permissions.js.map +1 -0
- package/build/admin/services/keycloak-admin.service.d.ts +64 -0
- package/build/admin/services/keycloak-admin.service.d.ts.map +1 -0
- package/build/admin/services/keycloak-admin.service.js +152 -0
- package/build/admin/services/keycloak-admin.service.js.map +1 -0
- package/build/decorators/auth-decorators.d.ts +217 -0
- package/build/decorators/auth-decorators.d.ts.map +1 -0
- package/build/decorators/auth-decorators.js +251 -0
- package/build/decorators/auth-decorators.js.map +1 -0
- package/build/decorators/context-utils.d.ts +101 -0
- package/build/decorators/context-utils.d.ts.map +1 -0
- package/build/decorators/context-utils.js +178 -0
- package/build/decorators/context-utils.js.map +1 -0
- package/build/decorators/graphql-auth-decorators.d.ts +144 -0
- package/build/decorators/graphql-auth-decorators.d.ts.map +1 -0
- package/build/decorators/graphql-auth-decorators.js +152 -0
- package/build/decorators/graphql-auth-decorators.js.map +1 -0
- package/build/decorators/index.d.ts +5 -0
- package/build/decorators/index.d.ts.map +1 -0
- package/build/decorators/index.js +4 -0
- package/build/decorators/index.js.map +1 -0
- package/build/guards/index.d.ts +4 -0
- package/build/guards/index.d.ts.map +1 -0
- package/build/guards/index.js +4 -0
- package/build/guards/index.js.map +1 -0
- package/build/guards/jwt-auth.guard.d.ts +52 -0
- package/build/guards/jwt-auth.guard.d.ts.map +1 -0
- package/build/guards/jwt-auth.guard.js +97 -0
- package/build/guards/jwt-auth.guard.js.map +1 -0
- package/build/guards/permission.guard.d.ts +37 -0
- package/build/guards/permission.guard.d.ts.map +1 -0
- package/build/guards/permission.guard.js +73 -0
- package/build/guards/permission.guard.js.map +1 -0
- package/build/guards/role.guard.d.ts +33 -0
- package/build/guards/role.guard.d.ts.map +1 -0
- package/build/guards/role.guard.js +69 -0
- package/build/guards/role.guard.js.map +1 -0
- package/build/index.d.ts +92 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +98 -0
- package/build/index.js.map +1 -0
- package/build/keycloak/index.d.ts +7 -0
- package/build/keycloak/index.d.ts.map +1 -0
- package/build/keycloak/index.js +5 -0
- package/build/keycloak/index.js.map +1 -0
- package/build/keycloak/keycloak.constants.d.ts +2 -0
- package/build/keycloak/keycloak.constants.d.ts.map +1 -0
- package/build/keycloak/keycloak.constants.js +2 -0
- package/build/keycloak/keycloak.constants.js.map +1 -0
- package/build/keycloak/keycloak.interfaces.d.ts +12 -0
- package/build/keycloak/keycloak.interfaces.d.ts.map +1 -0
- package/build/keycloak/keycloak.interfaces.js +2 -0
- package/build/keycloak/keycloak.interfaces.js.map +1 -0
- package/build/keycloak/keycloak.module.d.ts +56 -0
- package/build/keycloak/keycloak.module.d.ts.map +1 -0
- package/build/keycloak/keycloak.module.js +104 -0
- package/build/keycloak/keycloak.module.js.map +1 -0
- package/build/keycloak/keycloak.types.d.ts +60 -0
- package/build/keycloak/keycloak.types.d.ts.map +1 -0
- package/build/keycloak/keycloak.types.js +2 -0
- package/build/keycloak/keycloak.types.js.map +1 -0
- package/build/keycloak/services/jwks-cache.service.d.ts +64 -0
- package/build/keycloak/services/jwks-cache.service.d.ts.map +1 -0
- package/build/keycloak/services/jwks-cache.service.js +176 -0
- package/build/keycloak/services/jwks-cache.service.js.map +1 -0
- package/build/keycloak/services/keycloak-token-validation.service.d.ts +88 -0
- package/build/keycloak/services/keycloak-token-validation.service.d.ts.map +1 -0
- package/build/keycloak/services/keycloak-token-validation.service.js +243 -0
- package/build/keycloak/services/keycloak-token-validation.service.js.map +1 -0
- package/build/package.json +72 -0
- package/package.json +93 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Context Options for Authentication Decorators
|
|
4
|
+
*
|
|
5
|
+
* Defines options for context-aware parameter extraction in authentication decorators.
|
|
6
|
+
* Supports automatic context detection and explicit context type specification.
|
|
7
|
+
*/
|
|
8
|
+
export interface ContextOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The execution context type. If not specified, context will be auto-detected.
|
|
11
|
+
*/
|
|
12
|
+
contextType?: 'http' | 'graphql' | 'websocket' | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to auto-detect the context type. Defaults to true.
|
|
15
|
+
* When true, the decorator will automatically determine the context type.
|
|
16
|
+
* When false, the contextType must be explicitly specified.
|
|
17
|
+
*/
|
|
18
|
+
autoDetect?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Default context options with auto-detection enabled
|
|
22
|
+
*/
|
|
23
|
+
export declare const DEFAULT_CONTEXT_OPTIONS: ContextOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Detects the execution context type from the current ExecutionContext
|
|
26
|
+
*
|
|
27
|
+
* @param ctx - The NestJS execution context
|
|
28
|
+
* @returns The detected context type ('http', 'graphql', or 'websocket'); defaults to 'http' if undetermined
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const contextType = DetectContextType(ctx);
|
|
33
|
+
* if (contextType === 'graphql') {
|
|
34
|
+
* // Handle GraphQL context
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function DetectContextType(ctx: ExecutionContext): 'http' | 'graphql' | 'websocket';
|
|
39
|
+
/**
|
|
40
|
+
* Extracts the request object from any supported execution context
|
|
41
|
+
*
|
|
42
|
+
* @param ctx - The NestJS execution context
|
|
43
|
+
* @param options - Context options for extraction behavior
|
|
44
|
+
* @returns The request object from the appropriate context
|
|
45
|
+
* @throws Error if request cannot be extracted or context type is unsupported
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const request = extractRequestFromContext(ctx);
|
|
50
|
+
* const user = request.user;
|
|
51
|
+
* const token = request.headers.authorization;
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function ExtractRequestFromContext(ctx: ExecutionContext, options?: ContextOptions): any;
|
|
55
|
+
/**
|
|
56
|
+
* Extracts the authenticated user from any supported execution context
|
|
57
|
+
*
|
|
58
|
+
* @param ctx - The NestJS execution context
|
|
59
|
+
* @param options - Context options for extraction behavior
|
|
60
|
+
* @returns The authenticated user object or undefined if not found
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const user = extractUserFromContext(ctx);
|
|
65
|
+
* if (user) {
|
|
66
|
+
* console.log('User ID:', user.id);
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example With property path
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const userId = extractUserFromContext(ctx, { property: 'id' });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function ExtractUserFromContext(ctx: ExecutionContext, options?: ContextOptions & {
|
|
76
|
+
property?: string;
|
|
77
|
+
}): any;
|
|
78
|
+
/**
|
|
79
|
+
* Extracts the authorization token from any supported execution context
|
|
80
|
+
*
|
|
81
|
+
* @param ctx - The NestJS execution context
|
|
82
|
+
* @param options - Context options for extraction behavior
|
|
83
|
+
* @returns The authorization token string or undefined if not found
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const token = extractAuthTokenFromContext(ctx);
|
|
88
|
+
* if (token) {
|
|
89
|
+
* // Validate token
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function ExtractAuthTokenFromContext(ctx: ExecutionContext, options?: ContextOptions): string | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Backwards compatibility aliases - exported functions use PascalCase per project conventions
|
|
96
|
+
*/
|
|
97
|
+
export declare const detectContextType: typeof DetectContextType;
|
|
98
|
+
export declare const extractAuthTokenFromContext: typeof ExtractAuthTokenFromContext;
|
|
99
|
+
export declare const extractRequestFromContext: typeof ExtractRequestFromContext;
|
|
100
|
+
export declare const extractUserFromContext: typeof ExtractUserFromContext;
|
|
101
|
+
//# sourceMappingURL=context-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-utils.d.ts","sourceRoot":"","sources":["../../src/decorators/context-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC9B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;IAE3D;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,cAErC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAgCzF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,cAAwC,GAC/C,GAAG,CAwCL;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CACrC,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAA4B,GACvE,GAAG,CAsBL;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CAC1C,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,cAAwC,GAC/C,MAAM,GAAG,SAAS,CAoBpB;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,0BAAoB,CAAC;AACnD,eAAO,MAAM,2BAA2B,oCAA8B,CAAC;AACvE,eAAO,MAAM,yBAAyB,kCAA4B,CAAC;AACnE,eAAO,MAAM,sBAAsB,+BAAyB,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
2
|
+
/**
|
|
3
|
+
* Default context options with auto-detection enabled
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_CONTEXT_OPTIONS = {
|
|
6
|
+
autoDetect: true,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Detects the execution context type from the current ExecutionContext
|
|
10
|
+
*
|
|
11
|
+
* @param ctx - The NestJS execution context
|
|
12
|
+
* @returns The detected context type ('http', 'graphql', or 'websocket'); defaults to 'http' if undetermined
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const contextType = DetectContextType(ctx);
|
|
17
|
+
* if (contextType === 'graphql') {
|
|
18
|
+
* // Handle GraphQL context
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function DetectContextType(ctx) {
|
|
23
|
+
// Use the context type reported by NestJS rather than try/catch,
|
|
24
|
+
// because GqlExecutionContext.create() never throws - it always wraps the context.
|
|
25
|
+
const contextType = ctx.getType();
|
|
26
|
+
if (contextType === 'graphql') {
|
|
27
|
+
return 'graphql';
|
|
28
|
+
}
|
|
29
|
+
if (contextType === 'ws') {
|
|
30
|
+
return 'websocket';
|
|
31
|
+
}
|
|
32
|
+
if (contextType === 'http') {
|
|
33
|
+
return 'http';
|
|
34
|
+
}
|
|
35
|
+
// For GraphQL contexts using @nestjs/graphql, the type is 'graphql'
|
|
36
|
+
// but some setups may use 'http' with a GraphQL layer on top.
|
|
37
|
+
// Fall back to checking if GqlExecutionContext can extract GraphQL args.
|
|
38
|
+
try {
|
|
39
|
+
const gqlCtx = GqlExecutionContext.create(ctx);
|
|
40
|
+
const info = gqlCtx.getInfo();
|
|
41
|
+
if (info?.fieldName) {
|
|
42
|
+
return 'graphql';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Not a GraphQL context
|
|
47
|
+
}
|
|
48
|
+
// Default to http if we can't determine the type
|
|
49
|
+
return 'http';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Extracts the request object from any supported execution context
|
|
53
|
+
*
|
|
54
|
+
* @param ctx - The NestJS execution context
|
|
55
|
+
* @param options - Context options for extraction behavior
|
|
56
|
+
* @returns The request object from the appropriate context
|
|
57
|
+
* @throws Error if request cannot be extracted or context type is unsupported
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const request = extractRequestFromContext(ctx);
|
|
62
|
+
* const user = request.user;
|
|
63
|
+
* const token = request.headers.authorization;
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function ExtractRequestFromContext(ctx, options = DEFAULT_CONTEXT_OPTIONS) {
|
|
67
|
+
const contextType = options.autoDetect
|
|
68
|
+
? DetectContextType(ctx)
|
|
69
|
+
: options.contextType;
|
|
70
|
+
if (!contextType) {
|
|
71
|
+
throw new Error('Context type must be specified when autoDetect is false');
|
|
72
|
+
}
|
|
73
|
+
switch (contextType) {
|
|
74
|
+
case 'http':
|
|
75
|
+
return ctx.switchToHttp().getRequest();
|
|
76
|
+
case 'graphql': {
|
|
77
|
+
const gqlCtx = GqlExecutionContext.create(ctx);
|
|
78
|
+
return gqlCtx.getContext().req;
|
|
79
|
+
}
|
|
80
|
+
case 'websocket': {
|
|
81
|
+
const wsCtx = ctx.switchToWs();
|
|
82
|
+
const client = wsCtx.getClient();
|
|
83
|
+
// Socket.IO provides handshake data with headers; raw WebSockets use upgradeReq
|
|
84
|
+
// Attempt to return an object with headers for header-based auth extraction
|
|
85
|
+
if (client?.handshake) {
|
|
86
|
+
// Socket.IO client — has handshake with headers
|
|
87
|
+
return { headers: client.handshake.headers, ...client };
|
|
88
|
+
}
|
|
89
|
+
if (client?.upgradeReq?.headers) {
|
|
90
|
+
// Raw WS — has upgradeReq with headers
|
|
91
|
+
return { headers: client.upgradeReq.headers, ...client };
|
|
92
|
+
}
|
|
93
|
+
// Fallback to raw client if no headers available
|
|
94
|
+
return client;
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`Unsupported context type: ${contextType}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Extracts the authenticated user from any supported execution context
|
|
102
|
+
*
|
|
103
|
+
* @param ctx - The NestJS execution context
|
|
104
|
+
* @param options - Context options for extraction behavior
|
|
105
|
+
* @returns The authenticated user object or undefined if not found
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const user = extractUserFromContext(ctx);
|
|
110
|
+
* if (user) {
|
|
111
|
+
* console.log('User ID:', user.id);
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example With property path
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const userId = extractUserFromContext(ctx, { property: 'id' });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function ExtractUserFromContext(ctx, options = DEFAULT_CONTEXT_OPTIONS) {
|
|
121
|
+
const request = ExtractRequestFromContext(ctx, options);
|
|
122
|
+
if (!request) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
let { user } = request;
|
|
126
|
+
if (options.property && user) {
|
|
127
|
+
// Extract nested property using dot notation
|
|
128
|
+
const keys = options.property.split('.');
|
|
129
|
+
for (const key of keys) {
|
|
130
|
+
if (user && typeof user === 'object') {
|
|
131
|
+
user = user[key];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return user;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Extracts the authorization token from any supported execution context
|
|
142
|
+
*
|
|
143
|
+
* @param ctx - The NestJS execution context
|
|
144
|
+
* @param options - Context options for extraction behavior
|
|
145
|
+
* @returns The authorization token string or undefined if not found
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const token = extractAuthTokenFromContext(ctx);
|
|
150
|
+
* if (token) {
|
|
151
|
+
* // Validate token
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function ExtractAuthTokenFromContext(ctx, options = DEFAULT_CONTEXT_OPTIONS) {
|
|
156
|
+
const request = ExtractRequestFromContext(ctx, options);
|
|
157
|
+
if (!request) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
// Try different common header variations
|
|
161
|
+
const authHeader = request.headers?.authorization ??
|
|
162
|
+
request.headers?.Authorization ??
|
|
163
|
+
request.headers?.['authorization'] ??
|
|
164
|
+
request.headers?.['Authorization'];
|
|
165
|
+
if (typeof authHeader === 'string') {
|
|
166
|
+
// Remove 'Bearer ' prefix if present
|
|
167
|
+
return authHeader.replace(/^Bearer\s+/i, '');
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Backwards compatibility aliases - exported functions use PascalCase per project conventions
|
|
173
|
+
*/
|
|
174
|
+
export const detectContextType = DetectContextType;
|
|
175
|
+
export const extractAuthTokenFromContext = ExtractAuthTokenFromContext;
|
|
176
|
+
export const extractRequestFromContext = ExtractRequestFromContext;
|
|
177
|
+
export const extractUserFromContext = ExtractUserFromContext;
|
|
178
|
+
//# sourceMappingURL=context-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-utils.js","sourceRoot":"","sources":["../../src/decorators/context-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAsBtD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAmB;IACtD,UAAU,EAAE,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M,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;iBAAM,CAAC;gBACP,OAAO,SAAS,CAAC;YAClB,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,2BAA2B,CAC1C,GAAqB,EACrB,UAA0B,uBAAuB;IAEjD,MAAM,OAAO,GAAG,yBAAyB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAExD,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,yCAAyC;IACzC,MAAM,UAAU,GACf,OAAO,CAAC,OAAO,EAAE,aAAa;QAC9B,OAAO,CAAC,OAAO,EAAE,aAAa;QAC9B,OAAO,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC;QAClC,OAAO,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;IAEpC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACpC,qCAAqC;QACrC,OAAO,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AACnD,MAAM,CAAC,MAAM,2BAA2B,GAAG,2BAA2B,CAAC;AACvE,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAyB,CAAC;AACnE,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL Authentication Decorators
|
|
3
|
+
*
|
|
4
|
+
* These decorators provide GraphQL-specific authentication and authorization
|
|
5
|
+
* functionality by extending the base decorators with GraphQL context options.
|
|
6
|
+
* They maintain the same API as the base decorators but automatically configure
|
|
7
|
+
* for GraphQL execution context.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* GraphQL-specific Public decorator
|
|
13
|
+
*
|
|
14
|
+
* Marks GraphQL resolvers as publicly accessible, bypassing authentication.
|
|
15
|
+
* Equivalent to @Public() but explicitly configured for GraphQL context.
|
|
16
|
+
*
|
|
17
|
+
* @returns Method decorator that marks the GraphQL resolver as public
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* @GraphQLPublic()
|
|
22
|
+
* @Query(() => String)
|
|
23
|
+
* async getHealth(): Promise<string> {
|
|
24
|
+
* return 'OK';
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const GraphQLPublic: () => MethodDecorator;
|
|
29
|
+
/**
|
|
30
|
+
* GraphQL-specific Auth decorator
|
|
31
|
+
*
|
|
32
|
+
* Marks GraphQL resolvers as requiring authentication.
|
|
33
|
+
* Equivalent to @Auth() but explicitly configured for GraphQL context.
|
|
34
|
+
*
|
|
35
|
+
* @returns Method decorator that marks the GraphQL resolver as requiring authentication
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* @GraphQLAuth()
|
|
40
|
+
* @Query(() => User)
|
|
41
|
+
* async getCurrentUser(@GraphQLCurrentUser() user: User): Promise<User> {
|
|
42
|
+
* return user;
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const GraphQLAuth: () => MethodDecorator;
|
|
47
|
+
/**
|
|
48
|
+
* GraphQL-specific Roles decorator
|
|
49
|
+
*
|
|
50
|
+
* Specifies the roles required to access GraphQL resolvers.
|
|
51
|
+
* Equivalent to @Roles() but explicitly configured for GraphQL context.
|
|
52
|
+
*
|
|
53
|
+
* @param roles - Array of role names required for access
|
|
54
|
+
* @returns Method decorator that specifies role requirements for GraphQL resolvers
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* @GraphQLRoles('admin', 'moderator')
|
|
59
|
+
* @Query(() => [User])
|
|
60
|
+
* async getUsers(): Promise<User[]> {
|
|
61
|
+
* // Only users with 'admin' or 'moderator' roles can access
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const GraphQLRoles: (...roles: string[]) => MethodDecorator;
|
|
66
|
+
/**
|
|
67
|
+
* GraphQL-specific CurrentUser decorator
|
|
68
|
+
*
|
|
69
|
+
* Injects the currently authenticated user into GraphQL resolver parameters.
|
|
70
|
+
* Uses GraphQL context to extract the user object populated by authentication guards.
|
|
71
|
+
*
|
|
72
|
+
* @param property - Optional property path to extract from the user object (e.g., 'id', 'profile.name')
|
|
73
|
+
* @returns Parameter decorator that injects the current user from GraphQL context
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* @Query(() => User)
|
|
78
|
+
* async getCurrentUser(@GraphQLCurrentUser() user: User): Promise<User> {
|
|
79
|
+
* return user;
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example With property access
|
|
84
|
+
* ```typescript
|
|
85
|
+
* @Query(() => String)
|
|
86
|
+
* async getUserId(@GraphQLCurrentUser('id') userId: string): Promise<string> {
|
|
87
|
+
* return userId;
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function GraphQLCurrentUser(property?: string): ParameterDecorator;
|
|
92
|
+
/**
|
|
93
|
+
* GraphQL-specific AuthToken decorator
|
|
94
|
+
*
|
|
95
|
+
* Injects the authorization token from GraphQL request context headers.
|
|
96
|
+
* Useful for custom token validation in GraphQL resolvers.
|
|
97
|
+
*
|
|
98
|
+
* @returns Parameter decorator that injects the authorization token
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* @Query(() => Boolean)
|
|
103
|
+
* async validateToken(@GraphQLAuthToken() token: string): Promise<boolean> {
|
|
104
|
+
* return this.authService.validateToken(token);
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare const GraphQLAuthToken: () => ParameterDecorator;
|
|
109
|
+
/**
|
|
110
|
+
* GraphQL Context Parameter decorator
|
|
111
|
+
*
|
|
112
|
+
* Injects the entire GraphQL context object into resolver parameters.
|
|
113
|
+
* Provides access to request, response, and other context data in GraphQL resolvers.
|
|
114
|
+
*
|
|
115
|
+
* @returns Parameter decorator that injects the GraphQL context
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* @Query(() => String)
|
|
120
|
+
* async getRequestId(@GraphQLContextParam() context: any): Promise<string> {
|
|
121
|
+
* return context.req.headers['x-request-id'];
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare const GraphQLContextParam: () => ParameterDecorator;
|
|
126
|
+
/**
|
|
127
|
+
* GraphQL User alias for GraphQLCurrentUser
|
|
128
|
+
*
|
|
129
|
+
* Alternative name for GraphQLCurrentUser decorator specifically for GraphQL contexts.
|
|
130
|
+
* Provides the same functionality with a more explicit name.
|
|
131
|
+
*
|
|
132
|
+
* @param property - Optional property path to extract from the user object
|
|
133
|
+
* @returns Parameter decorator that injects the current user
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* @Query(() => User)
|
|
138
|
+
* async getCurrentUser(@GraphQLUser() user: User): Promise<User> {
|
|
139
|
+
* return user;
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare const GraphQLUser: typeof GraphQLCurrentUser;
|
|
144
|
+
//# sourceMappingURL=graphql-auth-decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-auth-decorators.d.ts","sourceRoot":"","sources":["../../src/decorators/graphql-auth-decorators.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,uBAAS,CAAC;AAEpC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,uBAAO,CAAC;AAEhC;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,yCAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAExE;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,QAAO,kBAA2D,CAAC;AAEhG;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,QAAO,kBAKpC,CAAC;AAEJ;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,2BAAqB,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createParamDecorator } from '@nestjs/common';
|
|
2
|
+
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
3
|
+
import { Auth, Public, Roles, CurrentUser, AuthToken } from './auth-decorators.js';
|
|
4
|
+
/**
|
|
5
|
+
* GraphQL Authentication Decorators
|
|
6
|
+
*
|
|
7
|
+
* These decorators provide GraphQL-specific authentication and authorization
|
|
8
|
+
* functionality by extending the base decorators with GraphQL context options.
|
|
9
|
+
* They maintain the same API as the base decorators but automatically configure
|
|
10
|
+
* for GraphQL execution context.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* GraphQL-specific Public decorator
|
|
16
|
+
*
|
|
17
|
+
* Marks GraphQL resolvers as publicly accessible, bypassing authentication.
|
|
18
|
+
* Equivalent to @Public() but explicitly configured for GraphQL context.
|
|
19
|
+
*
|
|
20
|
+
* @returns Method decorator that marks the GraphQL resolver as public
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* @GraphQLPublic()
|
|
25
|
+
* @Query(() => String)
|
|
26
|
+
* async getHealth(): Promise<string> {
|
|
27
|
+
* return 'OK';
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const GraphQLPublic = Public;
|
|
32
|
+
/**
|
|
33
|
+
* GraphQL-specific Auth decorator
|
|
34
|
+
*
|
|
35
|
+
* Marks GraphQL resolvers as requiring authentication.
|
|
36
|
+
* Equivalent to @Auth() but explicitly configured for GraphQL context.
|
|
37
|
+
*
|
|
38
|
+
* @returns Method decorator that marks the GraphQL resolver as requiring authentication
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* @GraphQLAuth()
|
|
43
|
+
* @Query(() => User)
|
|
44
|
+
* async getCurrentUser(@GraphQLCurrentUser() user: User): Promise<User> {
|
|
45
|
+
* return user;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const GraphQLAuth = Auth;
|
|
50
|
+
/**
|
|
51
|
+
* GraphQL-specific Roles decorator
|
|
52
|
+
*
|
|
53
|
+
* Specifies the roles required to access GraphQL resolvers.
|
|
54
|
+
* Equivalent to @Roles() but explicitly configured for GraphQL context.
|
|
55
|
+
*
|
|
56
|
+
* @param roles - Array of role names required for access
|
|
57
|
+
* @returns Method decorator that specifies role requirements for GraphQL resolvers
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* @GraphQLRoles('admin', 'moderator')
|
|
62
|
+
* @Query(() => [User])
|
|
63
|
+
* async getUsers(): Promise<User[]> {
|
|
64
|
+
* // Only users with 'admin' or 'moderator' roles can access
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export const GraphQLRoles = Roles;
|
|
69
|
+
/**
|
|
70
|
+
* GraphQL-specific CurrentUser decorator
|
|
71
|
+
*
|
|
72
|
+
* Injects the currently authenticated user into GraphQL resolver parameters.
|
|
73
|
+
* Uses GraphQL context to extract the user object populated by authentication guards.
|
|
74
|
+
*
|
|
75
|
+
* @param property - Optional property path to extract from the user object (e.g., 'id', 'profile.name')
|
|
76
|
+
* @returns Parameter decorator that injects the current user from GraphQL context
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* @Query(() => User)
|
|
81
|
+
* async getCurrentUser(@GraphQLCurrentUser() user: User): Promise<User> {
|
|
82
|
+
* return user;
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example With property access
|
|
87
|
+
* ```typescript
|
|
88
|
+
* @Query(() => String)
|
|
89
|
+
* async getUserId(@GraphQLCurrentUser('id') userId: string): Promise<string> {
|
|
90
|
+
* return userId;
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function GraphQLCurrentUser(property) {
|
|
95
|
+
return CurrentUser(property, { contextType: 'graphql' });
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* GraphQL-specific AuthToken decorator
|
|
99
|
+
*
|
|
100
|
+
* Injects the authorization token from GraphQL request context headers.
|
|
101
|
+
* Useful for custom token validation in GraphQL resolvers.
|
|
102
|
+
*
|
|
103
|
+
* @returns Parameter decorator that injects the authorization token
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* @Query(() => Boolean)
|
|
108
|
+
* async validateToken(@GraphQLAuthToken() token: string): Promise<boolean> {
|
|
109
|
+
* return this.authService.validateToken(token);
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export const GraphQLAuthToken = () => AuthToken({ contextType: 'graphql' });
|
|
114
|
+
/**
|
|
115
|
+
* GraphQL Context Parameter decorator
|
|
116
|
+
*
|
|
117
|
+
* Injects the entire GraphQL context object into resolver parameters.
|
|
118
|
+
* Provides access to request, response, and other context data in GraphQL resolvers.
|
|
119
|
+
*
|
|
120
|
+
* @returns Parameter decorator that injects the GraphQL context
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* @Query(() => String)
|
|
125
|
+
* async getRequestId(@GraphQLContextParam() context: any): Promise<string> {
|
|
126
|
+
* return context.req.headers['x-request-id'];
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export const GraphQLContextParam = () => createParamDecorator((_data, ctx) => {
|
|
131
|
+
const gqlCtx = GqlExecutionContext.create(ctx);
|
|
132
|
+
return gqlCtx.getContext();
|
|
133
|
+
})();
|
|
134
|
+
/**
|
|
135
|
+
* GraphQL User alias for GraphQLCurrentUser
|
|
136
|
+
*
|
|
137
|
+
* Alternative name for GraphQLCurrentUser decorator specifically for GraphQL contexts.
|
|
138
|
+
* Provides the same functionality with a more explicit name.
|
|
139
|
+
*
|
|
140
|
+
* @param property - Optional property path to extract from the user object
|
|
141
|
+
* @returns Parameter decorator that injects the current user
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* @Query(() => User)
|
|
146
|
+
* async getCurrentUser(@GraphQLUser() user: User): Promise<User> {
|
|
147
|
+
* return user;
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export const GraphQLUser = GraphQLCurrentUser;
|
|
152
|
+
//# sourceMappingURL=graphql-auth-decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-auth-decorators.js","sourceRoot":"","sources":["../../src/decorators/graphql-auth-decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;AACx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extractAuthTokenFromContext, } from './auth-decorators.js';
|
|
2
|
+
export type { ContextOptions } from './auth-decorators.js';
|
|
3
|
+
export { GraphQLPublic, GraphQLAuth, GraphQLRoles, GraphQLCurrentUser, GraphQLAuthToken, GraphQLContextParam, GraphQLUser, } from './graphql-auth-decorators.js';
|
|
4
|
+
export { ExtractRequestFromContext, ExtractUserFromContext, ExtractAuthTokenFromContext, DetectContextType } from './context-utils.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,IAAI,EACJ,MAAM,EACN,KAAK,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EACN,aAAa,EACb,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Auth, Public, Roles, Permissions, CurrentUser, AuthToken, IS_PUBLIC_KEY, ROLES_KEY, PERMISSIONS_KEY, detectContextType, extractRequestFromContext, extractUserFromContext, extractAuthTokenFromContext, } from './auth-decorators.js';
|
|
2
|
+
export { GraphQLPublic, GraphQLAuth, GraphQLRoles, GraphQLCurrentUser, GraphQLAuthToken, GraphQLContextParam, GraphQLUser, } from './graphql-auth-decorators.js';
|
|
3
|
+
export { ExtractRequestFromContext, ExtractUserFromContext, ExtractAuthTokenFromContext, DetectContextType } from './context-utils.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,IAAI,EACJ,MAAM,EACN,KAAK,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACN,aAAa,EACb,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|