@quatrain/auth 1.2.3 → 1.2.5

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.
@@ -102,4 +102,11 @@ export declare abstract class AbstractAuthAdapter implements AuthInterface {
102
102
  * @returns Action response from the provider.
103
103
  */
104
104
  abstract setCustomUserClaims(id: string, claims: any): any;
105
+ /**
106
+ * Initiates password recovery/reset process for a user.
107
+ *
108
+ * @param email - The user email.
109
+ * @param redirectTo - Optional redirect destination.
110
+ */
111
+ recoverPassword(email: string, redirectTo?: string): Promise<any>;
105
112
  }
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AbstractAuthAdapter = void 0;
13
13
  const Auth_1 = require("./Auth");
14
14
  const backend_1 = require("@quatrain/backend");
15
+ const http_1 = require("@quatrain/http");
15
16
  /**
16
17
  * Abstract base class that defines the contract for all authentication adapters.
17
18
  * Implementations should adapt standard authentication methods to specific providers
@@ -31,7 +32,7 @@ class AbstractAuthAdapter {
31
32
  middleware() {
32
33
  return (req, res) => __awaiter(this, void 0, void 0, function* () {
33
34
  var _a;
34
- const bearer = (((_a = req.headers) === null || _a === void 0 ? void 0 : _a.authorization) || '').split(' ')[1] || '';
35
+ const bearer = http_1.HttpHelper.parseBearerToken((_a = req.headers) === null || _a === void 0 ? void 0 : _a.authorization);
35
36
  if (bearer) {
36
37
  try {
37
38
  const user = yield this.getAuthToken(bearer);
@@ -44,7 +45,7 @@ class AbstractAuthAdapter {
44
45
  }
45
46
  }
46
47
  res.setHeader('WWW-Authenticate', 'Bearer realm="Core API"');
47
- res.status(401).send('Authentication required.');
48
+ res.status(http_1.HttpStatus.UNAUTHORIZED).send('Authentication required.');
48
49
  return false;
49
50
  });
50
51
  }
@@ -72,6 +73,15 @@ class AbstractAuthAdapter {
72
73
  get alias() {
73
74
  return this._alias;
74
75
  }
76
+ /**
77
+ * Initiates password recovery/reset process for a user.
78
+ *
79
+ * @param email - The user email.
80
+ * @param redirectTo - Optional redirect destination.
81
+ */
82
+ recoverPassword(email, redirectTo) {
83
+ throw new Error('Password recovery not implemented for this adapter');
84
+ }
75
85
  }
76
86
  exports.AbstractAuthAdapter = AbstractAuthAdapter;
77
87
  /** The `User` class reference to be used by the adapter. */
package/dist/Auth.d.ts CHANGED
@@ -37,6 +37,8 @@ export declare class Auth extends Core {
37
37
  static logger: any;
38
38
  /** Standardized error message for duplicate email constraint violations. */
39
39
  static ERROR_EMAIL_EXISTS: string;
40
+ /** Standardized error message for weak password / password complexity violations. */
41
+ static ERROR_WEAK_PASSWORD: string;
40
42
  protected static _providers: AuthRegistry<any>;
41
43
  /**
42
44
  * Registers a configured auth provider into the global context.
package/dist/Auth.js CHANGED
@@ -51,4 +51,6 @@ Auth.defaultProvider = 'default';
51
51
  Auth.logger = _a.addLogger('Auth');
52
52
  /** Standardized error message for duplicate email constraint violations. */
53
53
  Auth.ERROR_EMAIL_EXISTS = `User email already exists`;
54
+ /** Standardized error message for weak password / password complexity violations. */
55
+ Auth.ERROR_WEAK_PASSWORD = `weak_password`;
54
56
  Auth._providers = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "Auth adapters commons",
6
6
  "main": "dist/index.js",
@@ -20,9 +20,10 @@
20
20
  },
21
21
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
22
22
  "dependencies": {
23
- "@quatrain/api": "^1.1.5",
24
- "@quatrain/backend": "^1.2.11",
25
- "@quatrain/core": "^1.2.14"
23
+ "@quatrain/api": "^1.1.6",
24
+ "@quatrain/backend": "^1.2.14",
25
+ "@quatrain/core": "^1.2.16",
26
+ "@quatrain/http": "^1.0.1"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@tsconfig/recommended": "^1.0.1",
@@ -2,6 +2,7 @@ import { Auth, AuthParameters, AuthParametersKeys } from './Auth'
2
2
  import { User } from '@quatrain/backend'
3
3
  import { AuthInterface } from './types/AuthInterface'
4
4
  import { ApiMiddleware, ApiRequest, ApiResponse } from '@quatrain/api'
5
+ import { HttpStatus, HttpHelper } from '@quatrain/http'
5
6
 
6
7
  /**
7
8
  * Abstract base class that defines the contract for all authentication adapters.
@@ -25,7 +26,7 @@ export abstract class AbstractAuthAdapter implements AuthInterface {
25
26
  */
26
27
  public middleware(): ApiMiddleware {
27
28
  return async (req: ApiRequest, res: ApiResponse): Promise<boolean> => {
28
- const bearer = ((req.headers?.authorization as string) || '').split(' ')[1] || ''
29
+ const bearer = HttpHelper.parseBearerToken(req.headers?.authorization as string)
29
30
 
30
31
  if (bearer) {
31
32
  try {
@@ -39,7 +40,7 @@ export abstract class AbstractAuthAdapter implements AuthInterface {
39
40
  }
40
41
 
41
42
  res.setHeader('WWW-Authenticate', 'Bearer realm="Core API"')
42
- res.status(401).send('Authentication required.')
43
+ res.status(HttpStatus.UNAUTHORIZED).send('Authentication required.')
43
44
  return false
44
45
  }
45
46
  }
@@ -147,4 +148,14 @@ export abstract class AbstractAuthAdapter implements AuthInterface {
147
148
  * @returns Action response from the provider.
148
149
  */
149
150
  abstract setCustomUserClaims(id: string, claims: any): any
151
+
152
+ /**
153
+ * Initiates password recovery/reset process for a user.
154
+ *
155
+ * @param email - The user email.
156
+ * @param redirectTo - Optional redirect destination.
157
+ */
158
+ recoverPassword(email: string, redirectTo?: string): Promise<any> {
159
+ throw new Error('Password recovery not implemented for this adapter')
160
+ }
150
161
  }
package/src/Auth.ts CHANGED
@@ -48,6 +48,8 @@ export class Auth extends Core {
48
48
 
49
49
  /** Standardized error message for duplicate email constraint violations. */
50
50
  static ERROR_EMAIL_EXISTS = `User email already exists`
51
+ /** Standardized error message for weak password / password complexity violations. */
52
+ static ERROR_WEAK_PASSWORD = `weak_password`
51
53
 
52
54
  protected static _providers: AuthRegistry<any> = {}
53
55