@rxap/nest-auth0 10.1.0-dev.2 → 10.1.0-dev.4
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 +12 -0
- package/package.json +2 -2
- package/src/lib/auth0-module-options.factory.js +5 -1
- package/src/lib/auth0-options.d.ts +1 -0
- package/src/lib/auth0-validation-schema.d.ts +2 -1
- package/src/lib/auth0-validation-schema.js +1 -0
- package/src/lib/auth0.guard.d.ts +1 -0
- package/src/lib/auth0.guard.js +28 -0
- package/src/lib/auth0.module.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.1.0-dev.4](https://gitlab.com/rxap/packages/compare/@rxap/nest-auth0@10.1.0-dev.3...@rxap/nest-auth0@10.1.0-dev.4) (2025-03-27)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- export auth0 options token ([408dce2](https://gitlab.com/rxap/packages/commit/408dce21929006cacf8aef5e32af2517641df476))
|
|
11
|
+
|
|
12
|
+
# [10.1.0-dev.3](https://gitlab.com/rxap/packages/compare/@rxap/nest-auth0@10.1.0-dev.2...@rxap/nest-auth0@10.1.0-dev.3) (2025-03-27)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **auth0:** add support for optional Auth0 disable feature ([a3cef89](https://gitlab.com/rxap/packages/commit/a3cef895c6acc348097fb0a3c8df97df48a7d5dd))
|
|
17
|
+
|
|
6
18
|
# [10.1.0-dev.2](https://gitlab.com/rxap/packages/compare/@rxap/nest-auth0@10.1.0-dev.1...@rxap/nest-auth0@10.1.0-dev.2) (2025-03-17)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "10.1.0-dev.
|
|
2
|
+
"version": "10.1.0-dev.4",
|
|
3
3
|
"name": "@rxap/nest-auth0",
|
|
4
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",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"schematics": "./generators.json",
|
|
40
40
|
"type": "commonjs",
|
|
41
41
|
"types": "./src/index.d.ts",
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "9b4612051cfdc2777fa33b7a57abe7c860b342d2"
|
|
43
43
|
}
|
|
@@ -65,7 +65,11 @@ let Auth0ModuleOptionsFactory = class Auth0ModuleOptionsFactory {
|
|
|
65
65
|
clientId: this.config.get('AUTH0_CLIENT_ID'),
|
|
66
66
|
clientSecret: this.config.get('AUTH0_CLIENT_SECRET'),
|
|
67
67
|
};
|
|
68
|
-
return {
|
|
68
|
+
return {
|
|
69
|
+
authentication,
|
|
70
|
+
management,
|
|
71
|
+
disabled: this.config.get('AUTH0_DISABLED', false),
|
|
72
|
+
};
|
|
69
73
|
}
|
|
70
74
|
};
|
|
71
75
|
exports.Auth0ModuleOptionsFactory = Auth0ModuleOptionsFactory;
|
|
@@ -2,4 +2,5 @@ import { AuthenticationClientOptions, ManagementClientOptionsWithToken, Manageme
|
|
|
2
2
|
export interface Auth0Options {
|
|
3
3
|
authentication: AuthenticationClientOptions;
|
|
4
4
|
management: ManagementClientOptionsWithToken | ManagementClientOptionsWithClientCredentials;
|
|
5
|
+
disabled?: boolean;
|
|
5
6
|
}
|
|
@@ -26,6 +26,7 @@ export interface Auth0ValidationSchema {
|
|
|
26
26
|
AUTH0_CLIENT_ID: string;
|
|
27
27
|
AUTH0_CLIENT_SECRET: string;
|
|
28
28
|
AUTH0_MANAGEMENT_TOKEN: string;
|
|
29
|
+
AUTH0_DISABLED: boolean;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Generates a validation schema for Auth0 configuration settings using Joi.
|
|
@@ -35,4 +36,4 @@ export interface Auth0ValidationSchema {
|
|
|
35
36
|
* @param {Partial<Auth0ValidationSchema>} [defaults={}] - An optional object with default values for the schema keys.
|
|
36
37
|
* @return {Record<string, StringSchema>} The Joi validation schema object for Auth0 configuration.
|
|
37
38
|
*/
|
|
38
|
-
export declare function auth0ValidationSchema(environment: Environment, defaults?: Partial<Auth0ValidationSchema>): Record<string, Joi.
|
|
39
|
+
export declare function auth0ValidationSchema(environment: Environment, defaults?: Partial<Auth0ValidationSchema>): Record<string, Joi.AnySchema<any>>;
|
|
@@ -18,6 +18,7 @@ function auth0ValidationSchema(environment, defaults = {}) {
|
|
|
18
18
|
schema['AUTH0_CLIENT_ID'] = Joi.string();
|
|
19
19
|
schema['AUTH0_CLIENT_SECRET'] = Joi.string();
|
|
20
20
|
schema['AUTH0_MANAGEMENT_TOKEN'] = Joi.string();
|
|
21
|
+
schema['AUTH0_DISABLED'] = Joi.boolean();
|
|
21
22
|
for (const [key, value] of Object.keys(defaults)) {
|
|
22
23
|
if (value) {
|
|
23
24
|
schema[key] = schema[key].default(value);
|
package/src/lib/auth0.guard.d.ts
CHANGED
package/src/lib/auth0.guard.js
CHANGED
|
@@ -7,6 +7,7 @@ const core_1 = require("@nestjs/core");
|
|
|
7
7
|
const jwt_1 = require("@nestjs/jwt");
|
|
8
8
|
const nest_utilities_1 = require("@rxap/nest-utilities");
|
|
9
9
|
const passport_jwt_1 = require("passport-jwt");
|
|
10
|
+
const tokens_1 = require("./tokens");
|
|
10
11
|
let Auth0Guard = class Auth0Guard {
|
|
11
12
|
async canActivate(context) {
|
|
12
13
|
const isPublic = this.reflector.getAllAndOverride(nest_utilities_1.IS_PUBLIC_KEY, [
|
|
@@ -17,6 +18,29 @@ let Auth0Guard = class Auth0Guard {
|
|
|
17
18
|
return true;
|
|
18
19
|
}
|
|
19
20
|
const request = context.switchToHttp().getRequest();
|
|
21
|
+
if (this.options.disabled) {
|
|
22
|
+
this.logger.warn('Auth0 is disabled', 'Auth0Guard');
|
|
23
|
+
const user = request.user = {};
|
|
24
|
+
if (request.headers['x-user-id']) {
|
|
25
|
+
user.sub = request.headers['x-user-id'];
|
|
26
|
+
}
|
|
27
|
+
if (request.headers['x-user-sub']) {
|
|
28
|
+
user.sub = request.headers['x-user-sub'];
|
|
29
|
+
}
|
|
30
|
+
user.aud = request.headers['x-user-aud'];
|
|
31
|
+
user.roles = request.headers['x-user-roles'];
|
|
32
|
+
user.displayName = request.headers['x-user-display-name'];
|
|
33
|
+
user.email = request.headers['x-user-email'];
|
|
34
|
+
user.usernane = request.headers['x-user-username'];
|
|
35
|
+
user.name = request.headers['x-user-name'];
|
|
36
|
+
user.nickname = request.headers['x-user-nickname'];
|
|
37
|
+
if (request.user && 'sub' in request.user) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.logger.warn('Request is not authenticated. Please check the authorization header. Ensure the header x-user-id or x-user-sub is set. Fallback to bearer token authentication.', 'Auth0Guard');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
20
44
|
const jwt = passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken()(request);
|
|
21
45
|
if (!jwt) {
|
|
22
46
|
this.logger.debug('No Bearer token found in authorization header', 'Auth0Guard');
|
|
@@ -45,6 +69,10 @@ tslib_1.__decorate([
|
|
|
45
69
|
(0, common_1.Inject)(core_1.Reflector),
|
|
46
70
|
tslib_1.__metadata("design:type", core_1.Reflector)
|
|
47
71
|
], Auth0Guard.prototype, "reflector", void 0);
|
|
72
|
+
tslib_1.__decorate([
|
|
73
|
+
(0, common_1.Inject)(tokens_1.AUTH0_OPTIONS),
|
|
74
|
+
tslib_1.__metadata("design:type", Object)
|
|
75
|
+
], Auth0Guard.prototype, "options", void 0);
|
|
48
76
|
exports.Auth0Guard = Auth0Guard = tslib_1.__decorate([
|
|
49
77
|
(0, common_1.Injectable)()
|
|
50
78
|
], Auth0Guard);
|
package/src/lib/auth0.module.js
CHANGED
|
@@ -152,6 +152,7 @@ let Auth0Module = class Auth0Module extends exports.ConfigurableModuleClass {
|
|
|
152
152
|
module.exports ??= [];
|
|
153
153
|
module.exports.push(auth0_authentication_service_1.Auth0AuthenticationService);
|
|
154
154
|
module.exports.push(auth0_management_service_1.Auth0ManagementService);
|
|
155
|
+
module.exports.push(tokens_1.AUTH0_OPTIONS);
|
|
155
156
|
return module;
|
|
156
157
|
}
|
|
157
158
|
};
|