@rxap/nest-auth0 10.0.0-dev.3 → 10.0.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/CHANGELOG.md +8 -0
- package/generators.json +14 -1
- package/package.json +4 -2
- package/src/generators/init/generator.d.ts +4 -0
- package/src/generators/init/generator.js +97 -0
- package/src/generators/init/index.d.ts +2 -0
- package/src/generators/init/index.js +6 -0
- package/src/lib/auth0-module-options.factory.d.ts +45 -0
- package/src/lib/auth0-module-options.factory.js +45 -0
- package/src/lib/auth0-validation-schema.d.ts +16 -0
- package/src/lib/auth0-validation-schema.js +16 -0
- package/src/lib/auth0.module.d.ts +104 -0
- package/src/lib/auth0.module.js +104 -0
- package/src/lib/auth0.service.d.ts +60 -0
- package/src/lib/auth0.service.js +60 -0
- package/src/lib/jwt.strategy.d.ts +65 -0
- package/src/lib/jwt.strategy.js +65 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [10.0.0](https://gitlab.com/rxap/packages/compare/@rxap/nest-auth0@10.0.0-dev.4...@rxap/nest-auth0@10.0.0) (2025-02-13)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rxap/nest-auth0
|
|
9
|
+
|
|
10
|
+
# [10.0.0-dev.4](https://gitlab.com/rxap/packages/compare/@rxap/nest-auth0@10.0.0-dev.3...@rxap/nest-auth0@10.0.0-dev.4) (2025-02-13)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @rxap/nest-auth0
|
|
13
|
+
|
|
6
14
|
# [10.0.0-dev.3](https://gitlab.com/rxap/packages/compare/@rxap/nest-auth0@10.0.0-dev.2...@rxap/nest-auth0@10.0.0-dev.3) (2025-02-10)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @rxap/nest-auth0
|
package/generators.json
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
2
|
+
"generators": {
|
|
3
|
+
"init": {
|
|
4
|
+
"factory": "./src/generators/init/generator",
|
|
5
|
+
"schema": "./src/generators/init/schema.json",
|
|
6
|
+
"description": "Initialize the package in the workspace"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"schematics": {
|
|
10
|
+
"init": {
|
|
11
|
+
"factory": "./src/generators/init/index",
|
|
12
|
+
"schema": "./src/generators/init/schema.json",
|
|
13
|
+
"description": "Initialize the package in the workspace"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
3
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "10.0.0
|
|
2
|
+
"version": "10.0.0",
|
|
3
3
|
"name": "@rxap/nest-auth0",
|
|
4
|
+
"description": "This package provides an Auth0 module for NestJS applications, simplifying integration with Auth0 for authentication and authorization. It includes a configurable module, JWT strategy, and service for interacting with the Auth0 Authentication API. The module also offers validation schemas for environment variables related to Auth0 configuration.\n",
|
|
4
5
|
"license": "GPL-3.0-or-later",
|
|
5
6
|
"dependencies": {
|
|
6
7
|
"@nestjs/passport": "^11.0.5",
|
|
@@ -35,7 +36,8 @@
|
|
|
35
36
|
"url": "https://gitlab.com/rxap/packages.git",
|
|
36
37
|
"directory": "packages/nest/auth0"
|
|
37
38
|
},
|
|
39
|
+
"schematics": "./generators.json",
|
|
38
40
|
"type": "commonjs",
|
|
39
41
|
"types": "./src/index.d.ts",
|
|
40
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "753c877fe1a5c2fcfa737310f6e99fd1371f9b4d"
|
|
41
43
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initGenerator = initGenerator;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
async function initGenerator(tree, options) {
|
|
7
|
+
const packageJsonFilePath = (0, path_1.relative)(tree.root, (0, path_1.join)(__dirname, '..', '..', '..', 'package.json'));
|
|
8
|
+
if (!tree.exists(packageJsonFilePath)) {
|
|
9
|
+
console.error('package.json not found in: ' + packageJsonFilePath);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const { peerDependencies, name: packageName } = JSON.parse(tree.read(packageJsonFilePath, 'utf-8'));
|
|
13
|
+
console.log(`Coerce peer dependencies for package: ${packageName}`);
|
|
14
|
+
if (!peerDependencies || !Object.keys(peerDependencies).length) {
|
|
15
|
+
console.log('No peer dependencies found');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
console.log(`Peer dependencies: ${Object.keys(peerDependencies).join(', ')}`);
|
|
19
|
+
const rootPackageJson = JSON.parse(tree.read('package.json', 'utf-8'));
|
|
20
|
+
let isDevDependency = !!rootPackageJson.devDependencies?.[packageName];
|
|
21
|
+
if (isDevDependency &&
|
|
22
|
+
[/^@rxap\/ngx/, /^@rxap\/nest/].some((rx) => rx.test(packageName))) {
|
|
23
|
+
rootPackageJson.dependencies ??= {};
|
|
24
|
+
rootPackageJson.dependencies[packageName] =
|
|
25
|
+
rootPackageJson.devDependencies[packageName];
|
|
26
|
+
delete rootPackageJson.devDependencies[packageName];
|
|
27
|
+
isDevDependency = false;
|
|
28
|
+
tree.write('package.json', JSON.stringify(rootPackageJson, null, 2));
|
|
29
|
+
}
|
|
30
|
+
if (!isDevDependency && [
|
|
31
|
+
/^@rxap\/plugin/,
|
|
32
|
+
/^@rxap\/workspace/,
|
|
33
|
+
/@rxap\/schematic/,
|
|
34
|
+
]) {
|
|
35
|
+
rootPackageJson.devDependencies ??= {};
|
|
36
|
+
rootPackageJson.devDependencies[packageName] =
|
|
37
|
+
rootPackageJson.dependencies[packageName];
|
|
38
|
+
delete rootPackageJson.dependencies[packageName];
|
|
39
|
+
isDevDependency = true;
|
|
40
|
+
tree.write('package.json', JSON.stringify(rootPackageJson, null, 2));
|
|
41
|
+
}
|
|
42
|
+
const missingPeerDependencies = Object.entries(peerDependencies)
|
|
43
|
+
.filter(([dep]) => !rootPackageJson.dependencies?.[dep] &&
|
|
44
|
+
!rootPackageJson.devDependencies?.[dep])
|
|
45
|
+
.reduce((acc, [dep, version]) => ({ ...acc, [dep]: version }), {});
|
|
46
|
+
if (!Object.keys(missingPeerDependencies).length) {
|
|
47
|
+
console.log('No missing peer dependencies');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (isDevDependency) {
|
|
51
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, missingPeerDependencies);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, missingPeerDependencies, {});
|
|
55
|
+
}
|
|
56
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
57
|
+
(0, devkit_1.installPackagesTask)(tree);
|
|
58
|
+
for (const peer of Object.keys(missingPeerDependencies)) {
|
|
59
|
+
console.log(`Peer dependency ${peer} added to package.json`);
|
|
60
|
+
const peerPackageJsonFilePath = (0, path_1.join)('node_modules', ...peer.split('/'), 'package.json');
|
|
61
|
+
if (!tree.exists(peerPackageJsonFilePath)) {
|
|
62
|
+
console.log(`Peer dependency ${peer} has no package.json`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const { generators, schematics } = JSON.parse(tree.read(peerPackageJsonFilePath, 'utf-8'));
|
|
66
|
+
if (!generators && !schematics) {
|
|
67
|
+
console.log(`Peer dependency ${peer} has no generators or schematics`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const configFile = generators || schematics;
|
|
71
|
+
if (!tree.exists((0, path_1.join)('node_modules', ...peer.split('/'), configFile))) {
|
|
72
|
+
console.log(`Peer dependency ${peer} has no generators or schematics file`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const config = JSON.parse(tree.read((0, path_1.join)('node_modules', ...peer.split('/'), configFile), 'utf-8'));
|
|
76
|
+
if (!config.generators?.init) {
|
|
77
|
+
console.log(`Peer dependency ${peer} has no init generator`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const initGeneratorFilePath = config.generators.init.factory;
|
|
81
|
+
const fullInitGeneratorFilePath = (0, path_1.join)('node_modules', ...peer.split('/'), initGeneratorFilePath) + '.js';
|
|
82
|
+
if (!tree.exists(fullInitGeneratorFilePath)) {
|
|
83
|
+
console.log(`Peer dependency ${peer} has no init generator file: ` +
|
|
84
|
+
fullInitGeneratorFilePath);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
88
|
+
const initGenerator = require((0, path_1.join)('node_modules', ...peer.split('/'), initGeneratorFilePath))?.default;
|
|
89
|
+
if (typeof initGenerator !== 'function') {
|
|
90
|
+
console.log(`Peer dependency ${peer} has no init generator function`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
console.log(`Run init generator for peer dependency ${peer}`);
|
|
94
|
+
await initGenerator(tree, options);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.default = initGenerator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const generator_1 = require("./generator");
|
|
5
|
+
const schematic = (0, devkit_1.convertNxGenerator)(generator_1.default);
|
|
6
|
+
exports.default = schematic;
|
|
@@ -1,8 +1,53 @@
|
|
|
1
1
|
import { ConfigurableModuleOptionsFactory, Logger } from '@nestjs/common';
|
|
2
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
3
|
import { AuthenticationClientOptions } from 'auth0';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an instance of `AuthenticationClientOptions` for Auth0 configuration.
|
|
6
|
+
*
|
|
7
|
+
* @summary
|
|
8
|
+
* This factory class is responsible for providing the configuration options required to initialize the Auth0 client.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - The type of the options to be created.
|
|
11
|
+
* @typeParam K - The method name used to create the options.
|
|
12
|
+
*
|
|
13
|
+
* @throws {@link Error} if any required configuration values are missing.
|
|
14
|
+
*
|
|
15
|
+
* @property config - The configuration service used to retrieve Auth0 settings.
|
|
16
|
+
* @property logger - The logger instance used for logging information during the creation of options.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const factory = new Auth0ModuleOptionsFactory();
|
|
21
|
+
* const options = await factory.create();
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @summary
|
|
25
|
+
* This method retrieves configuration values from the `ConfigService` and constructs an `AuthenticationClientOptions` object.
|
|
26
|
+
*
|
|
27
|
+
* @returns A promise that resolves to an `AuthenticationClientOptions` object containing the Auth0 configuration.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const options = await auth0ModuleOptionsFactory.create();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
4
34
|
export declare class Auth0ModuleOptionsFactory implements ConfigurableModuleOptionsFactory<AuthenticationClientOptions, 'create'> {
|
|
5
35
|
protected readonly config: ConfigService;
|
|
6
36
|
protected readonly logger: Logger;
|
|
37
|
+
/**
|
|
38
|
+
* Creates the authentication client options for Auth0.
|
|
39
|
+
*
|
|
40
|
+
* @summary
|
|
41
|
+
* This method retrieves configuration values from the `ConfigService` and constructs an `AuthenticationClientOptions` object.
|
|
42
|
+
*
|
|
43
|
+
* @returns A promise that resolves to an `AuthenticationClientOptions` object containing the Auth0 configuration.
|
|
44
|
+
*
|
|
45
|
+
* @throws {@link Error} if any required configuration values are missing.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const options = await auth0ModuleOptionsFactory.create();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
7
52
|
create(): Promise<AuthenticationClientOptions>;
|
|
8
53
|
}
|
|
@@ -4,7 +4,52 @@ exports.Auth0ModuleOptionsFactory = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const config_1 = require("@nestjs/config");
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of `AuthenticationClientOptions` for Auth0 configuration.
|
|
9
|
+
*
|
|
10
|
+
* @summary
|
|
11
|
+
* This factory class is responsible for providing the configuration options required to initialize the Auth0 client.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - The type of the options to be created.
|
|
14
|
+
* @typeParam K - The method name used to create the options.
|
|
15
|
+
*
|
|
16
|
+
* @throws {@link Error} if any required configuration values are missing.
|
|
17
|
+
*
|
|
18
|
+
* @property config - The configuration service used to retrieve Auth0 settings.
|
|
19
|
+
* @property logger - The logger instance used for logging information during the creation of options.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const factory = new Auth0ModuleOptionsFactory();
|
|
24
|
+
* const options = await factory.create();
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @summary
|
|
28
|
+
* This method retrieves configuration values from the `ConfigService` and constructs an `AuthenticationClientOptions` object.
|
|
29
|
+
*
|
|
30
|
+
* @returns A promise that resolves to an `AuthenticationClientOptions` object containing the Auth0 configuration.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const options = await auth0ModuleOptionsFactory.create();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
7
37
|
let Auth0ModuleOptionsFactory = class Auth0ModuleOptionsFactory {
|
|
38
|
+
/**
|
|
39
|
+
* Creates the authentication client options for Auth0.
|
|
40
|
+
*
|
|
41
|
+
* @summary
|
|
42
|
+
* This method retrieves configuration values from the `ConfigService` and constructs an `AuthenticationClientOptions` object.
|
|
43
|
+
*
|
|
44
|
+
* @returns A promise that resolves to an `AuthenticationClientOptions` object containing the Auth0 configuration.
|
|
45
|
+
*
|
|
46
|
+
* @throws {@link Error} if any required configuration values are missing.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const options = await auth0ModuleOptionsFactory.create();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
8
53
|
async create() {
|
|
9
54
|
this.logger.verbose('Create auth0 client options', 'Auth0ClientModuleOptionsFactory');
|
|
10
55
|
return {
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import { Environment } from '@rxap/nest-utilities';
|
|
2
2
|
import * as Joi from 'joi';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a Joi validation schema for Auth0 configuration values based on the provided environment.
|
|
5
|
+
*
|
|
6
|
+
* @param environment - The environment parameters that may influence the validation schema.
|
|
7
|
+
*
|
|
8
|
+
* @returns A Joi schema map that defines validation rules for the following Auth0 configuration keys:
|
|
9
|
+
* - `AUTH0_ISSUER_URL`: Must be a string.
|
|
10
|
+
* - `AUTH0_AUDIENCE`: Must be a string.
|
|
11
|
+
* - `AUTH0_DOMAIN`: Must be a string and a valid domain.
|
|
12
|
+
* - `AUTH0_CLIENT_ID`: Must be a string.
|
|
13
|
+
* - `AUTH0_CLIENT_SECRET`: Must be a string.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const schema = auth0ValidationSchema(environment);
|
|
18
|
+
*/
|
|
3
19
|
export declare function auth0ValidationSchema(environment: Environment): Joi.PartialSchemaMap<any>;
|
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.auth0ValidationSchema = auth0ValidationSchema;
|
|
4
4
|
const Joi = require("joi");
|
|
5
|
+
/**
|
|
6
|
+
* Generates a Joi validation schema for Auth0 configuration values based on the provided environment.
|
|
7
|
+
*
|
|
8
|
+
* @param environment - The environment parameters that may influence the validation schema.
|
|
9
|
+
*
|
|
10
|
+
* @returns A Joi schema map that defines validation rules for the following Auth0 configuration keys:
|
|
11
|
+
* - `AUTH0_ISSUER_URL`: Must be a string.
|
|
12
|
+
* - `AUTH0_AUDIENCE`: Must be a string.
|
|
13
|
+
* - `AUTH0_DOMAIN`: Must be a string and a valid domain.
|
|
14
|
+
* - `AUTH0_CLIENT_ID`: Must be a string.
|
|
15
|
+
* - `AUTH0_CLIENT_SECRET`: Must be a string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const schema = auth0ValidationSchema(environment);
|
|
20
|
+
*/
|
|
5
21
|
function auth0ValidationSchema(environment) {
|
|
6
22
|
const schema = {};
|
|
7
23
|
schema['AUTH0_ISSUER_URL'] = Joi.string();
|
|
@@ -1,8 +1,112 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import { AuthenticationClientOptions } from 'auth0';
|
|
3
3
|
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<AuthenticationClientOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: AuthenticationClientOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<AuthenticationClientOptions, "create"> & Partial<{}>;
|
|
4
|
+
/**
|
|
5
|
+
* A configurable module that provides Auth0 authentication services for NestJS applications.
|
|
6
|
+
*
|
|
7
|
+
* @summary
|
|
8
|
+
* This module provides authentication services using Auth0, including JWT strategy implementation and Auth0 service configuration.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - The type of authentication client options used to configure the Auth0 service.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Auth0Module } from './auth0.module';
|
|
15
|
+
*
|
|
16
|
+
* @Module({
|
|
17
|
+
* imports: [
|
|
18
|
+
* Auth0Module.register({
|
|
19
|
+
* domain: 'your-auth0-domain',
|
|
20
|
+
* clientId: 'your-client-id',
|
|
21
|
+
* clientSecret: 'your-client-secret',
|
|
22
|
+
* }),
|
|
23
|
+
* ],
|
|
24
|
+
* })
|
|
25
|
+
* export class AppModule {}
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { Auth0Module } from './auth0.module';
|
|
31
|
+
*
|
|
32
|
+
* @Module({
|
|
33
|
+
* imports: [
|
|
34
|
+
* Auth0Module.registerAsync({
|
|
35
|
+
* useFactory: async (configService: ConfigService) => ({
|
|
36
|
+
* domain: configService.get('AUTH0_DOMAIN'),
|
|
37
|
+
* clientId: configService.get('AUTH0_CLIENT_ID'),
|
|
38
|
+
* clientSecret: configService.get('AUTH0_CLIENT_SECRET'),
|
|
39
|
+
* }),
|
|
40
|
+
* inject: [ConfigService],
|
|
41
|
+
* }),
|
|
42
|
+
* ],
|
|
43
|
+
* })
|
|
44
|
+
* export class AppModule {}
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @property register - Static method to configure the module with synchronous options
|
|
48
|
+
* @property registerAsync - Static method to configure the module with asynchronous options
|
|
49
|
+
* @property updateProviders - Private static method to update the module's providers and exports
|
|
50
|
+
*
|
|
51
|
+
* @returns A dynamic module configured with Auth0 authentication capabilities, including the Auth0Service and JWT strategy.
|
|
52
|
+
*
|
|
53
|
+
* @throws {@link Error} If the required Auth0 configuration options are invalid or missing.
|
|
54
|
+
*/
|
|
4
55
|
export declare class Auth0Module extends ConfigurableModuleClass {
|
|
56
|
+
/**
|
|
57
|
+
* Registers the Auth0 module with the specified options.
|
|
58
|
+
*
|
|
59
|
+
* @summary This method allows for the configuration of the Auth0 module, enabling the use of the Auth0 service and its associated providers.
|
|
60
|
+
*
|
|
61
|
+
* @param options - The options for configuring the Auth0 module.
|
|
62
|
+
*
|
|
63
|
+
* @returns A dynamic module that includes the Auth0 service and the necessary providers.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { Auth0Module } from './auth0.module';
|
|
68
|
+
*
|
|
69
|
+
* const auth0Module = Auth0Module.register({
|
|
70
|
+
* domain: 'your-auth0-domain',
|
|
71
|
+
* clientId: 'your-client-id',
|
|
72
|
+
* clientSecret: 'your-client-secret',
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
5
76
|
static register(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
77
|
+
/**
|
|
78
|
+
* Provides asynchronous configuration options for the Auth0 module.
|
|
79
|
+
*
|
|
80
|
+
* @summary This method allows for dynamic configuration of the Auth0 module, enabling the use of asynchronous providers.
|
|
81
|
+
*
|
|
82
|
+
* @param options - The options for configuring the module asynchronously. This can include factory functions, dependency injection tokens, and other async configuration patterns.
|
|
83
|
+
*
|
|
84
|
+
* @returns A dynamic module that includes the Auth0 service and any other providers specified in the options.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* Auth0Module.registerAsync({
|
|
89
|
+
* useFactory: async () => ({
|
|
90
|
+
* domain: 'example.auth0.com',
|
|
91
|
+
* clientId: 'your-client-id',
|
|
92
|
+
* clientSecret: 'your-client-secret',
|
|
93
|
+
* }),
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* Auth0Module.registerAsync({
|
|
100
|
+
* imports: [ConfigModule],
|
|
101
|
+
* useFactory: async (configService: ConfigService) => ({
|
|
102
|
+
* domain: configService.get('AUTH0_DOMAIN'),
|
|
103
|
+
* clientId: configService.get('AUTH0_CLIENT_ID'),
|
|
104
|
+
* clientSecret: configService.get('AUTH0_CLIENT_SECRET'),
|
|
105
|
+
* }),
|
|
106
|
+
* inject: [ConfigService],
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
6
110
|
static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
7
111
|
private static updateProviders;
|
|
8
112
|
}
|
package/src/lib/auth0.module.js
CHANGED
|
@@ -10,10 +10,114 @@ const jwt_strategy_1 = require("./jwt.strategy");
|
|
|
10
10
|
const tokens_1 = require("./tokens");
|
|
11
11
|
_a = new common_1.ConfigurableModuleBuilder()
|
|
12
12
|
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
13
|
+
/**
|
|
14
|
+
* A configurable module that provides Auth0 authentication services for NestJS applications.
|
|
15
|
+
*
|
|
16
|
+
* @summary
|
|
17
|
+
* This module provides authentication services using Auth0, including JWT strategy implementation and Auth0 service configuration.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam T - The type of authentication client options used to configure the Auth0 service.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { Auth0Module } from './auth0.module';
|
|
24
|
+
*
|
|
25
|
+
* @Module({
|
|
26
|
+
* imports: [
|
|
27
|
+
* Auth0Module.register({
|
|
28
|
+
* domain: 'your-auth0-domain',
|
|
29
|
+
* clientId: 'your-client-id',
|
|
30
|
+
* clientSecret: 'your-client-secret',
|
|
31
|
+
* }),
|
|
32
|
+
* ],
|
|
33
|
+
* })
|
|
34
|
+
* export class AppModule {}
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { Auth0Module } from './auth0.module';
|
|
40
|
+
*
|
|
41
|
+
* @Module({
|
|
42
|
+
* imports: [
|
|
43
|
+
* Auth0Module.registerAsync({
|
|
44
|
+
* useFactory: async (configService: ConfigService) => ({
|
|
45
|
+
* domain: configService.get('AUTH0_DOMAIN'),
|
|
46
|
+
* clientId: configService.get('AUTH0_CLIENT_ID'),
|
|
47
|
+
* clientSecret: configService.get('AUTH0_CLIENT_SECRET'),
|
|
48
|
+
* }),
|
|
49
|
+
* inject: [ConfigService],
|
|
50
|
+
* }),
|
|
51
|
+
* ],
|
|
52
|
+
* })
|
|
53
|
+
* export class AppModule {}
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @property register - Static method to configure the module with synchronous options
|
|
57
|
+
* @property registerAsync - Static method to configure the module with asynchronous options
|
|
58
|
+
* @property updateProviders - Private static method to update the module's providers and exports
|
|
59
|
+
*
|
|
60
|
+
* @returns A dynamic module configured with Auth0 authentication capabilities, including the Auth0Service and JWT strategy.
|
|
61
|
+
*
|
|
62
|
+
* @throws {@link Error} If the required Auth0 configuration options are invalid or missing.
|
|
63
|
+
*/
|
|
13
64
|
let Auth0Module = class Auth0Module extends exports.ConfigurableModuleClass {
|
|
65
|
+
/**
|
|
66
|
+
* Registers the Auth0 module with the specified options.
|
|
67
|
+
*
|
|
68
|
+
* @summary This method allows for the configuration of the Auth0 module, enabling the use of the Auth0 service and its associated providers.
|
|
69
|
+
*
|
|
70
|
+
* @param options - The options for configuring the Auth0 module.
|
|
71
|
+
*
|
|
72
|
+
* @returns A dynamic module that includes the Auth0 service and the necessary providers.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { Auth0Module } from './auth0.module';
|
|
77
|
+
*
|
|
78
|
+
* const auth0Module = Auth0Module.register({
|
|
79
|
+
* domain: 'your-auth0-domain',
|
|
80
|
+
* clientId: 'your-client-id',
|
|
81
|
+
* clientSecret: 'your-client-secret',
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
14
85
|
static register(options) {
|
|
15
86
|
return this.updateProviders(super.register(options));
|
|
16
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Provides asynchronous configuration options for the Auth0 module.
|
|
90
|
+
*
|
|
91
|
+
* @summary This method allows for dynamic configuration of the Auth0 module, enabling the use of asynchronous providers.
|
|
92
|
+
*
|
|
93
|
+
* @param options - The options for configuring the module asynchronously. This can include factory functions, dependency injection tokens, and other async configuration patterns.
|
|
94
|
+
*
|
|
95
|
+
* @returns A dynamic module that includes the Auth0 service and any other providers specified in the options.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* Auth0Module.registerAsync({
|
|
100
|
+
* useFactory: async () => ({
|
|
101
|
+
* domain: 'example.auth0.com',
|
|
102
|
+
* clientId: 'your-client-id',
|
|
103
|
+
* clientSecret: 'your-client-secret',
|
|
104
|
+
* }),
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* Auth0Module.registerAsync({
|
|
111
|
+
* imports: [ConfigModule],
|
|
112
|
+
* useFactory: async (configService: ConfigService) => ({
|
|
113
|
+
* domain: configService.get('AUTH0_DOMAIN'),
|
|
114
|
+
* clientId: configService.get('AUTH0_CLIENT_ID'),
|
|
115
|
+
* clientSecret: configService.get('AUTH0_CLIENT_SECRET'),
|
|
116
|
+
* }),
|
|
117
|
+
* inject: [ConfigService],
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
17
121
|
static registerAsync(options) {
|
|
18
122
|
return this.updateProviders(super.registerAsync(options));
|
|
19
123
|
}
|
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
import { AuthenticationClient, AuthenticationClientOptions } from 'auth0';
|
|
2
|
+
/**
|
|
3
|
+
* A service that extends Auth0's AuthenticationClient to provide authentication capabilities in NestJS applications.
|
|
4
|
+
*
|
|
5
|
+
* @summary
|
|
6
|
+
* Provides Auth0 authentication services with additional token management functionality.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T - The type of authentication client options used to configure the Auth0 service.
|
|
9
|
+
*
|
|
10
|
+
* @param options - The configuration options for the Auth0 client including domain, clientId, and clientSecret.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @Injectable()
|
|
15
|
+
* class AppService {
|
|
16
|
+
* constructor(private readonly auth0Service: Auth0Service) {}
|
|
17
|
+
*
|
|
18
|
+
* async getToken() {
|
|
19
|
+
* return this.auth0Service.requestToken('https://api.example.com');
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Manual instantiation (not recommended in NestJS)
|
|
27
|
+
* const auth0Service = new Auth0Service({
|
|
28
|
+
* domain: 'your-domain.auth0.com',
|
|
29
|
+
* clientId: 'your-client-id',
|
|
30
|
+
* clientSecret: 'your-client-secret'
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @throws {@link Error} If the Auth0 client initialization fails due to invalid configuration options.
|
|
35
|
+
*
|
|
36
|
+
* @property requestToken - Method to obtain an access token for a specific audience using client credentials flow.
|
|
37
|
+
*/
|
|
2
38
|
export declare class Auth0Service extends AuthenticationClient {
|
|
3
39
|
constructor(options: AuthenticationClientOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Requests an access token from Auth0 using the client credentials grant flow.
|
|
42
|
+
*
|
|
43
|
+
* @summary
|
|
44
|
+
* This method obtains an access token for a specific API audience using the OAuth 2.0 client credentials flow.
|
|
45
|
+
*
|
|
46
|
+
* @param audience - The unique identifier of the API for which the access token is being requested. This is typically the API's URL or identifier registered in Auth0.
|
|
47
|
+
*
|
|
48
|
+
* @returns A Promise that resolves to a string containing the JWT access token that can be used to authenticate requests to the specified API audience.
|
|
49
|
+
*
|
|
50
|
+
* @throws {@link Error} If the token request fails due to invalid credentials, network issues, or other Auth0 API errors.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const auth0Service = new Auth0Service(options);
|
|
55
|
+
* try {
|
|
56
|
+
* const token = await auth0Service.requestToken('https://api.example.com');
|
|
57
|
+
* // Use the token for API requests
|
|
58
|
+
* console.log(token);
|
|
59
|
+
* } catch (error) {
|
|
60
|
+
* console.error('Failed to obtain access token:', error);
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
4
64
|
requestToken(audience: string): Promise<string>;
|
|
5
65
|
}
|
package/src/lib/auth0.service.js
CHANGED
|
@@ -5,10 +5,70 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const auth0_1 = require("auth0");
|
|
7
7
|
const tokens_1 = require("./tokens");
|
|
8
|
+
/**
|
|
9
|
+
* A service that extends Auth0's AuthenticationClient to provide authentication capabilities in NestJS applications.
|
|
10
|
+
*
|
|
11
|
+
* @summary
|
|
12
|
+
* Provides Auth0 authentication services with additional token management functionality.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam T - The type of authentication client options used to configure the Auth0 service.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The configuration options for the Auth0 client including domain, clientId, and clientSecret.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Injectable()
|
|
21
|
+
* class AppService {
|
|
22
|
+
* constructor(private readonly auth0Service: Auth0Service) {}
|
|
23
|
+
*
|
|
24
|
+
* async getToken() {
|
|
25
|
+
* return this.auth0Service.requestToken('https://api.example.com');
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Manual instantiation (not recommended in NestJS)
|
|
33
|
+
* const auth0Service = new Auth0Service({
|
|
34
|
+
* domain: 'your-domain.auth0.com',
|
|
35
|
+
* clientId: 'your-client-id',
|
|
36
|
+
* clientSecret: 'your-client-secret'
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @throws {@link Error} If the Auth0 client initialization fails due to invalid configuration options.
|
|
41
|
+
*
|
|
42
|
+
* @property requestToken - Method to obtain an access token for a specific audience using client credentials flow.
|
|
43
|
+
*/
|
|
8
44
|
let Auth0Service = class Auth0Service extends auth0_1.AuthenticationClient {
|
|
9
45
|
constructor(options) {
|
|
10
46
|
super(options);
|
|
11
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Requests an access token from Auth0 using the client credentials grant flow.
|
|
50
|
+
*
|
|
51
|
+
* @summary
|
|
52
|
+
* This method obtains an access token for a specific API audience using the OAuth 2.0 client credentials flow.
|
|
53
|
+
*
|
|
54
|
+
* @param audience - The unique identifier of the API for which the access token is being requested. This is typically the API's URL or identifier registered in Auth0.
|
|
55
|
+
*
|
|
56
|
+
* @returns A Promise that resolves to a string containing the JWT access token that can be used to authenticate requests to the specified API audience.
|
|
57
|
+
*
|
|
58
|
+
* @throws {@link Error} If the token request fails due to invalid credentials, network issues, or other Auth0 API errors.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const auth0Service = new Auth0Service(options);
|
|
63
|
+
* try {
|
|
64
|
+
* const token = await auth0Service.requestToken('https://api.example.com');
|
|
65
|
+
* // Use the token for API requests
|
|
66
|
+
* console.log(token);
|
|
67
|
+
* } catch (error) {
|
|
68
|
+
* console.error('Failed to obtain access token:', error);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
12
72
|
async requestToken(audience) {
|
|
13
73
|
const { data: { access_token }, } = await this.oauth.clientCredentialsGrant({ audience });
|
|
14
74
|
return access_token;
|
|
@@ -3,9 +3,74 @@ import { Strategy } from 'passport-jwt';
|
|
|
3
3
|
declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
|
|
4
4
|
validate(...args: any[]): unknown;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Here's the TSDoc documentation for the `JwtStrategy` class:
|
|
8
|
+
*
|
|
9
|
+
* A JWT (JSON Web Token) strategy implementation for authentication using Passport.js in NestJS applications.
|
|
10
|
+
*
|
|
11
|
+
* @summary
|
|
12
|
+
* This class implements the JWT strategy for authentication, integrating with Auth0's JWKS (JSON Web Key Set) for token validation.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { JwtStrategy } from './jwt.strategy';
|
|
17
|
+
*
|
|
18
|
+
* @Module({
|
|
19
|
+
* providers: [JwtStrategy],
|
|
20
|
+
* })
|
|
21
|
+
* export class AuthModule {
|
|
22
|
+
* constructor(private readonly jwtStrategy: JwtStrategy) {}
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Using the strategy in a guard
|
|
29
|
+
* @Injectable()
|
|
30
|
+
* export class JwtAuthGuard extends AuthGuard('jwt') {
|
|
31
|
+
* constructor(private jwtStrategy: JwtStrategy) {
|
|
32
|
+
* super();
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @throws {@link Error} If the configuration parameters for Auth0 are invalid or missing
|
|
38
|
+
* @throws {@link Error} If the JWT token validation fails
|
|
39
|
+
* @throws {@link Error} If the JWKS endpoint is unreachable or returns invalid data
|
|
40
|
+
*
|
|
41
|
+
* @property logger - A NestJS logger instance for verbose logging of validation operations
|
|
42
|
+
* @property validate - Method to validate the JWT payload and return the verified token contents
|
|
43
|
+
*
|
|
44
|
+
* @returns An instance of the JWT strategy that can be used for token validation in passport-based authentication
|
|
45
|
+
*/
|
|
6
46
|
export declare class JwtStrategy extends JwtStrategy_base {
|
|
7
47
|
private readonly logger;
|
|
8
48
|
constructor(config: ConfigService);
|
|
49
|
+
/**
|
|
50
|
+
* Here's the TSDoc documentation for the `validate` method:
|
|
51
|
+
*
|
|
52
|
+
* Validates the JWT payload received from the authentication process.
|
|
53
|
+
*
|
|
54
|
+
* @summary
|
|
55
|
+
* Performs validation of the decoded JWT payload and logs the validation process for debugging purposes.
|
|
56
|
+
*
|
|
57
|
+
* @param payload - The decoded JWT token payload to be validated. This can contain any JWT claims such as subject, issuer, or custom claims.
|
|
58
|
+
*
|
|
59
|
+
* @returns The validated payload object that will be attached to the request object for use in subsequent request handlers.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const jwtStrategy = new JwtStrategy(configService);
|
|
64
|
+
* const payload = await jwtStrategy.validate({
|
|
65
|
+
* sub: '123456789',
|
|
66
|
+
* email: 'user@example.com',
|
|
67
|
+
* permissions: ['read:users']
|
|
68
|
+
* });
|
|
69
|
+
* // payload will be available in your request object
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @throws {@link Error} If the payload fails validation or contains invalid claims.
|
|
73
|
+
*/
|
|
9
74
|
validate(payload: unknown): unknown;
|
|
10
75
|
}
|
|
11
76
|
export {};
|
package/src/lib/jwt.strategy.js
CHANGED
|
@@ -7,6 +7,46 @@ const config_1 = require("@nestjs/config");
|
|
|
7
7
|
const passport_1 = require("@nestjs/passport");
|
|
8
8
|
const passport_jwt_1 = require("passport-jwt");
|
|
9
9
|
const jwks_rsa_1 = require("jwks-rsa");
|
|
10
|
+
/**
|
|
11
|
+
* Here's the TSDoc documentation for the `JwtStrategy` class:
|
|
12
|
+
*
|
|
13
|
+
* A JWT (JSON Web Token) strategy implementation for authentication using Passport.js in NestJS applications.
|
|
14
|
+
*
|
|
15
|
+
* @summary
|
|
16
|
+
* This class implements the JWT strategy for authentication, integrating with Auth0's JWKS (JSON Web Key Set) for token validation.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { JwtStrategy } from './jwt.strategy';
|
|
21
|
+
*
|
|
22
|
+
* @Module({
|
|
23
|
+
* providers: [JwtStrategy],
|
|
24
|
+
* })
|
|
25
|
+
* export class AuthModule {
|
|
26
|
+
* constructor(private readonly jwtStrategy: JwtStrategy) {}
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Using the strategy in a guard
|
|
33
|
+
* @Injectable()
|
|
34
|
+
* export class JwtAuthGuard extends AuthGuard('jwt') {
|
|
35
|
+
* constructor(private jwtStrategy: JwtStrategy) {
|
|
36
|
+
* super();
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @throws {@link Error} If the configuration parameters for Auth0 are invalid or missing
|
|
42
|
+
* @throws {@link Error} If the JWT token validation fails
|
|
43
|
+
* @throws {@link Error} If the JWKS endpoint is unreachable or returns invalid data
|
|
44
|
+
*
|
|
45
|
+
* @property logger - A NestJS logger instance for verbose logging of validation operations
|
|
46
|
+
* @property validate - Method to validate the JWT payload and return the verified token contents
|
|
47
|
+
*
|
|
48
|
+
* @returns An instance of the JWT strategy that can be used for token validation in passport-based authentication
|
|
49
|
+
*/
|
|
10
50
|
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
11
51
|
constructor(config) {
|
|
12
52
|
super({
|
|
@@ -22,6 +62,31 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
22
62
|
algorithms: ['RS256'],
|
|
23
63
|
});
|
|
24
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Here's the TSDoc documentation for the `validate` method:
|
|
67
|
+
*
|
|
68
|
+
* Validates the JWT payload received from the authentication process.
|
|
69
|
+
*
|
|
70
|
+
* @summary
|
|
71
|
+
* Performs validation of the decoded JWT payload and logs the validation process for debugging purposes.
|
|
72
|
+
*
|
|
73
|
+
* @param payload - The decoded JWT token payload to be validated. This can contain any JWT claims such as subject, issuer, or custom claims.
|
|
74
|
+
*
|
|
75
|
+
* @returns The validated payload object that will be attached to the request object for use in subsequent request handlers.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const jwtStrategy = new JwtStrategy(configService);
|
|
80
|
+
* const payload = await jwtStrategy.validate({
|
|
81
|
+
* sub: '123456789',
|
|
82
|
+
* email: 'user@example.com',
|
|
83
|
+
* permissions: ['read:users']
|
|
84
|
+
* });
|
|
85
|
+
* // payload will be available in your request object
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @throws {@link Error} If the payload fails validation or contains invalid claims.
|
|
89
|
+
*/
|
|
25
90
|
validate(payload) {
|
|
26
91
|
this.logger.verbose('validate: %JSON', payload, 'JwtStrategy');
|
|
27
92
|
return payload;
|