@soapjs/soap-auth 0.3.1 → 0.3.2

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.
Files changed (121) hide show
  1. package/build/__tests__/soap-auth.test.d.ts +1 -0
  2. package/build/__tests__/soap-auth.test.js +42 -0
  3. package/build/errors.d.ts +14 -3
  4. package/build/errors.js +29 -8
  5. package/build/index.d.ts +1 -1
  6. package/build/index.js +1 -1
  7. package/build/services/__tests__/account-lock.service.test.d.ts +1 -0
  8. package/build/services/__tests__/account-lock.service.test.js +55 -0
  9. package/build/services/__tests__/auth-throttle.service.test.d.ts +1 -0
  10. package/build/services/__tests__/auth-throttle.service.test.js +48 -0
  11. package/build/services/__tests__/jwks.service.test.d.ts +1 -0
  12. package/build/services/__tests__/jwks.service.test.js +39 -0
  13. package/build/services/__tests__/mfa.service.test.d.ts +1 -0
  14. package/build/services/__tests__/mfa.service.test.js +66 -0
  15. package/build/services/__tests__/password.service.test.d.ts +1 -0
  16. package/build/services/__tests__/password.service.test.js +66 -0
  17. package/build/services/__tests__/pkce.service.test.d.ts +1 -0
  18. package/build/services/__tests__/pkce.service.test.js +77 -0
  19. package/build/services/__tests__/rate-limit.service.test.d.ts +1 -0
  20. package/build/services/__tests__/rate-limit.service.test.js +37 -0
  21. package/build/services/__tests__/role.service.test.d.ts +1 -0
  22. package/build/services/__tests__/role.service.test.js +31 -0
  23. package/build/services/account-lock.service.d.ts +12 -0
  24. package/build/services/account-lock.service.js +39 -0
  25. package/build/services/auth-throttle.service.d.ts +10 -0
  26. package/build/services/auth-throttle.service.js +43 -0
  27. package/build/services/index.d.ts +8 -0
  28. package/build/{factories → services}/index.js +8 -3
  29. package/build/services/jwks.service.d.ts +7 -0
  30. package/build/services/jwks.service.js +41 -0
  31. package/build/services/mfa.service.d.ts +12 -0
  32. package/build/services/mfa.service.js +74 -0
  33. package/build/services/password.service.d.ts +14 -0
  34. package/build/services/password.service.js +78 -0
  35. package/build/services/pkce.service.d.ts +14 -0
  36. package/build/services/pkce.service.js +81 -0
  37. package/build/services/rate-limit.service.d.ts +9 -0
  38. package/build/services/rate-limit.service.js +26 -0
  39. package/build/services/role.service.d.ts +9 -0
  40. package/build/services/role.service.js +26 -0
  41. package/build/session/__tests__/file.session-store.test.d.ts +1 -0
  42. package/build/session/__tests__/file.session-store.test.js +117 -0
  43. package/build/session/__tests__/memory.session-store.test.d.ts +1 -0
  44. package/build/session/__tests__/memory.session-store.test.js +77 -0
  45. package/build/session/__tests__/session-handler.test.d.ts +1 -0
  46. package/build/session/__tests__/session-handler.test.js +337 -0
  47. package/build/session/file.session-store.d.ts +1 -0
  48. package/build/session/file.session-store.js +7 -0
  49. package/build/session/memory.session-store.d.ts +4 -1
  50. package/build/session/memory.session-store.js +11 -5
  51. package/build/session/session-handler.d.ts +12 -7
  52. package/build/session/session-handler.js +46 -13
  53. package/build/session/session.errors.d.ts +6 -0
  54. package/build/session/session.errors.js +15 -0
  55. package/build/soap-auth.d.ts +9 -8
  56. package/build/soap-auth.js +42 -29
  57. package/build/strategies/__tests__/base-auth.strategy.test.d.ts +14 -0
  58. package/build/strategies/__tests__/base-auth.strategy.test.js +137 -0
  59. package/build/strategies/__tests__/credential-auth.strategy.test.d.ts +14 -0
  60. package/build/strategies/__tests__/credential-auth.strategy.test.js +265 -0
  61. package/build/strategies/__tests__/token-auth.strategy.test.d.ts +28 -0
  62. package/build/strategies/__tests__/token-auth.strategy.test.js +298 -0
  63. package/build/strategies/api-key/__tests__/api-key.strategy.test.d.ts +1 -0
  64. package/build/strategies/api-key/__tests__/api-key.strategy.test.js +103 -0
  65. package/build/strategies/api-key/api-key.strategy.d.ts +5 -2
  66. package/build/strategies/api-key/api-key.strategy.js +43 -35
  67. package/build/strategies/api-key/api-key.tools.d.ts +2 -0
  68. package/build/strategies/api-key/api-key.tools.js +39 -0
  69. package/build/strategies/api-key/api-key.types.d.ts +10 -2
  70. package/build/strategies/base-auth.strategy.d.ts +11 -5
  71. package/build/strategies/base-auth.strategy.js +45 -52
  72. package/build/strategies/basic/__tests__/basic.strategy.test.d.ts +1 -0
  73. package/build/strategies/basic/__tests__/basic.strategy.test.js +104 -0
  74. package/build/strategies/basic/basic.strategy.d.ts +5 -7
  75. package/build/strategies/basic/basic.strategy.js +6 -6
  76. package/build/strategies/basic/basic.tools.d.ts +2 -0
  77. package/build/strategies/basic/basic.tools.js +44 -0
  78. package/build/strategies/credential-auth.strategy.d.ts +7 -17
  79. package/build/strategies/credential-auth.strategy.js +116 -181
  80. package/build/strategies/jwt/__tests__/jwt.strategy.test.d.ts +1 -0
  81. package/build/strategies/jwt/__tests__/jwt.strategy.test.js +156 -0
  82. package/build/strategies/jwt/__tests__/jwt.tools.test.d.ts +1 -0
  83. package/build/strategies/jwt/__tests__/jwt.tools.test.js +98 -0
  84. package/build/strategies/jwt/jwt.strategy.d.ts +13 -14
  85. package/build/strategies/jwt/jwt.strategy.js +57 -44
  86. package/build/strategies/jwt/jwt.tools.d.ts +20 -7
  87. package/build/strategies/jwt/jwt.tools.js +180 -81
  88. package/build/strategies/local/__tests__/local.strategy.test.d.ts +1 -0
  89. package/build/strategies/local/__tests__/local.strategy.test.js +115 -0
  90. package/build/strategies/local/local.strategy.d.ts +4 -3
  91. package/build/strategies/local/local.strategy.js +7 -6
  92. package/build/strategies/local/local.tools.d.ts +2 -0
  93. package/build/strategies/local/local.tools.js +44 -0
  94. package/build/strategies/oauth2/hybrid.oauth2.strategy.d.ts +5 -0
  95. package/build/strategies/oauth2/hybrid.oauth2.strategy.js +92 -0
  96. package/build/strategies/oauth2/oauth2.errors.d.ts +12 -0
  97. package/build/strategies/oauth2/oauth2.errors.js +24 -0
  98. package/build/strategies/oauth2/oauth2.strategy.d.ts +25 -15
  99. package/build/strategies/oauth2/oauth2.strategy.js +131 -141
  100. package/build/strategies/oauth2/oauth2.tools.d.ts +7 -2
  101. package/build/strategies/oauth2/oauth2.tools.js +119 -14
  102. package/build/strategies/oauth2/oauth2.types.d.ts +32 -1
  103. package/build/strategies/token-auth.strategy.d.ts +14 -8
  104. package/build/strategies/token-auth.strategy.js +162 -38
  105. package/build/tools/index.d.ts +0 -2
  106. package/build/tools/index.js +0 -2
  107. package/build/tools/tools.d.ts +2 -1
  108. package/build/tools/tools.js +9 -12
  109. package/build/types.d.ts +88 -57
  110. package/package.json +1 -1
  111. package/build/factories/auth-strategy.factory.d.ts +0 -9
  112. package/build/factories/auth-strategy.factory.js +0 -16
  113. package/build/factories/http-auth-strategy.factory.d.ts +0 -5
  114. package/build/factories/http-auth-strategy.factory.js +0 -41
  115. package/build/factories/index.d.ts +0 -3
  116. package/build/factories/socket-auth-strategy.factory.d.ts +0 -5
  117. package/build/factories/socket-auth-strategy.factory.js +0 -27
  118. package/build/tools/session.tools.d.ts +0 -6
  119. package/build/tools/session.tools.js +0 -15
  120. package/build/tools/token.tools.d.ts +0 -7
  121. package/build/tools/token.tools.js +0 -32
@@ -1,70 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseAuthStrategy = void 0;
4
- const errors_1 = require("../errors");
4
+ const session_errors_1 = require("../session/session.errors");
5
+ const account_lock_service_1 = require("../services/account-lock.service");
6
+ const mfa_service_1 = require("../services/mfa.service");
7
+ const rate_limit_service_1 = require("../services/rate-limit.service");
8
+ const role_service_1 = require("../services/role.service");
9
+ const auth_throttle_service_1 = require("../services/auth-throttle.service");
5
10
  class BaseAuthStrategy {
6
11
  config;
7
12
  session;
8
13
  logger;
14
+ accountLock;
15
+ mfa;
16
+ rateLimit;
17
+ role;
18
+ throttle;
9
19
  constructor(config, session, logger) {
10
20
  this.config = config;
11
21
  this.session = session;
12
22
  this.logger = logger;
13
- }
14
- async init() {
15
- return Promise.resolve();
16
- }
17
- async isAccountLocked(account) {
18
- if (await this.config.lock.isAccountLocked?.(account)) {
19
- throw new errors_1.AccountLockedError();
23
+ if (config.mfa) {
24
+ this.mfa = new mfa_service_1.MfaService(config.mfa, logger);
20
25
  }
21
- return false;
22
- }
23
- async isAuthorized(user) {
24
- if (this.config.role.authorizeByRoles && this.config.role.roles) {
25
- const hasAccess = await this.config.role.authorizeByRoles(user, this.config.role.roles);
26
- if (!hasAccess) {
27
- throw new errors_1.UnauthorizedRoleError();
28
- }
26
+ if (config.lock) {
27
+ this.accountLock = new account_lock_service_1.AccountLockService(config.lock, logger);
29
28
  }
30
- return true;
31
- }
32
- async checkRateLimit(data) {
33
- if (this.config.rateLimit.checkRateLimit &&
34
- (await this.config.rateLimit.checkRateLimit(data))) {
35
- throw new errors_1.RateLimitExceededError();
29
+ if (config.rateLimit) {
30
+ this.rateLimit = new rate_limit_service_1.RateLimitService(config.rateLimit, logger);
36
31
  }
37
- }
38
- async checkMfa(user, context) {
39
- try {
40
- if (this.config.mfa?.isMfaRequired?.(user)) {
41
- const mfaCode = this.config.mfa?.extractMfaCode?.(context);
42
- if (!mfaCode) {
43
- await this.config.mfa.sendMfaCode?.(user, context);
44
- throw new Error("2FA required. A verification code has been sent.");
45
- }
46
- const attempts = (await this.config.mfa.getMfaAttempts?.(user)) || 0;
47
- if (this.config.mfa.maxMfaAttempts &&
48
- attempts >= this.config.mfa.maxMfaAttempts) {
49
- this.logger?.warn(`User ${user} exceeded maximum MFA attempts.`);
50
- await this.config.mfa.lockMfaOnFailure?.(user);
51
- throw new Error("Your account has been temporarily locked due to too many failed 2FA attempts.");
52
- }
53
- const isValidMfa = await this.config.mfa.validateMfaCode?.(user, mfaCode);
54
- if (!isValidMfa) {
55
- this.logger?.warn(`Invalid MFA code attempt for user: ${user}`);
56
- await this.config.mfa.incrementMfaAttempts?.(user);
57
- throw new Error("Invalid 2FA code provided.");
58
- }
59
- await this.config.mfa.resetMfaAttempts?.(user);
60
- this.logger?.info(`2FA successfully validated for user: ${user}`);
61
- }
32
+ if (config.role) {
33
+ this.role = new role_service_1.RoleService(config.role, logger);
62
34
  }
63
- catch (error) {
64
- this.logger?.error(`2FA validation error for user: ${user}`, error);
65
- throw error;
35
+ if (config.throttle) {
36
+ this.throttle = new auth_throttle_service_1.AuthThrottleService(config.throttle, logger);
66
37
  }
67
38
  }
39
+ async init() {
40
+ return Promise.resolve();
41
+ }
68
42
  async onSuccess(action, context) {
69
43
  try {
70
44
  await this.config.onSuccess?.(action, context);
@@ -74,11 +48,30 @@ class BaseAuthStrategy {
74
48
  }
75
49
  }
76
50
  async onFailure(action, context) {
51
+ this.logger?.error(`${action} failed:`, context.error);
77
52
  try {
78
53
  await this.config.onFailure?.(action, context);
79
54
  }
80
- catch (error) {
81
- this.logger?.error(error);
55
+ catch (e) {
56
+ this.logger?.error(e);
57
+ }
58
+ }
59
+ async authenticateWithSession(context) {
60
+ if (this.rateLimit) {
61
+ await this.rateLimit.checkRateLimit(context);
62
+ }
63
+ if (this.session) {
64
+ let sessionId = this.session.getSessionId(context);
65
+ if (!sessionId)
66
+ throw new session_errors_1.MissingSessionIdError();
67
+ const sessionData = await this.session.getSessionData(sessionId);
68
+ if (!sessionData)
69
+ throw new session_errors_1.InvalidSessionError();
70
+ const user = sessionData.user;
71
+ if (this.role) {
72
+ await this.role.isAuthorized(user);
73
+ }
74
+ return { user };
82
75
  }
83
76
  }
84
77
  }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const basic_strategy_1 = require("../basic.strategy");
4
+ const errors_1 = require("../../../errors");
5
+ describe("BasicStrategy", () => {
6
+ let strategy;
7
+ let mockConfig;
8
+ let mockSession;
9
+ let mockJwt;
10
+ beforeEach(() => {
11
+ mockConfig = {
12
+ credentials: {
13
+ extractCredentials: jest.fn(),
14
+ verifyCredentials: jest.fn(),
15
+ },
16
+ user: {
17
+ fetchUser: jest.fn(),
18
+ },
19
+ routes: {
20
+ login: {},
21
+ logout: {},
22
+ },
23
+ };
24
+ mockSession = {
25
+ issueSession: jest.fn(),
26
+ };
27
+ mockJwt = {
28
+ issueTokens: jest.fn(),
29
+ };
30
+ strategy = new basic_strategy_1.BasicStrategy(mockConfig, mockSession, mockJwt);
31
+ });
32
+ describe("extractCredentials", () => {
33
+ it("should extract credentials from Authorization header", () => {
34
+ mockConfig.credentials.extractCredentials = null;
35
+ const username = "testuser";
36
+ const password = "securepassword";
37
+ const encoded = Buffer.from(`${username}:${password}`).toString("base64");
38
+ const context = { headers: { authorization: `Basic ${encoded}` } };
39
+ const credentials = strategy.extractCredentials(context);
40
+ expect(credentials).toEqual({ identifier: username, password });
41
+ });
42
+ it("should throw MissingCredentialsError if Authorization header is missing", () => {
43
+ const context = { headers: {} };
44
+ expect(() => strategy.extractCredentials(context)).toThrow(errors_1.MissingCredentialsError);
45
+ });
46
+ it("should throw InvalidCredentialsError if Authorization header is malformed", () => {
47
+ const context = { headers: { authorization: "Bearer token" } };
48
+ mockConfig.credentials.extractCredentials = null;
49
+ expect(() => strategy.extractCredentials(context)).toThrow(errors_1.InvalidCredentialsError);
50
+ });
51
+ it("should throw InvalidCredentialsError if Authorization header is not base64-encoded properly", () => {
52
+ const context = { headers: { authorization: "Basic not_base64_data" } };
53
+ mockConfig.credentials.extractCredentials = null;
54
+ expect(() => strategy.extractCredentials(context)).toThrow(errors_1.InvalidCredentialsError);
55
+ });
56
+ it("should throw InvalidCredentialsError if decoded credentials are invalid", () => {
57
+ const encoded = Buffer.from(`username`).toString("base64");
58
+ const context = { headers: { authorization: `Basic ${encoded}` } };
59
+ mockConfig.credentials.extractCredentials = null;
60
+ expect(() => strategy.extractCredentials(context)).toThrow(errors_1.InvalidCredentialsError);
61
+ });
62
+ });
63
+ describe("verifyCredentials", () => {
64
+ it("should verify valid credentials", async () => {
65
+ mockConfig.credentials.verifyCredentials.mockResolvedValue(true);
66
+ const result = await strategy.verifyCredentials("testuser", "password");
67
+ expect(result).toBe(true);
68
+ expect(mockConfig.credentials.verifyCredentials).toHaveBeenCalledWith("testuser", "password");
69
+ });
70
+ it("should return false if credentials are invalid", async () => {
71
+ mockConfig.credentials.verifyCredentials.mockResolvedValue(false);
72
+ const result = await strategy.verifyCredentials("testuser", "wrongpass");
73
+ expect(result).toBe(false);
74
+ expect(mockConfig.credentials.verifyCredentials).toHaveBeenCalledWith("testuser", "wrongpass");
75
+ });
76
+ });
77
+ describe("fetchUser", () => {
78
+ it("should retrieve user data when credentials are valid", async () => {
79
+ const mockUser = { id: 1, username: "testuser" };
80
+ mockConfig.user.fetchUser.mockResolvedValue(mockUser);
81
+ const user = await strategy.fetchUser({
82
+ identifier: "testuser",
83
+ password: "securepassword",
84
+ });
85
+ expect(user).toEqual(mockUser);
86
+ expect(mockConfig.user.fetchUser).toHaveBeenCalledWith({
87
+ identifier: "testuser",
88
+ password: "securepassword",
89
+ });
90
+ });
91
+ it("should return null if user is not found", async () => {
92
+ mockConfig.user.fetchUser.mockResolvedValue(null);
93
+ const user = await strategy.fetchUser({
94
+ identifier: "unknownuser",
95
+ password: "securepassword",
96
+ });
97
+ expect(user).toBeNull();
98
+ expect(mockConfig.user.fetchUser).toHaveBeenCalledWith({
99
+ identifier: "unknownuser",
100
+ password: "securepassword",
101
+ });
102
+ });
103
+ });
104
+ });
@@ -1,19 +1,17 @@
1
1
  import * as Soap from "@soapjs/soap";
2
2
  import { CredentialAuthStrategy } from "../credential-auth.strategy";
3
- import { BasicContext, BasicStrategyConfig } from "./basic.types";
3
+ import { BasicStrategyConfig } from "./basic.types";
4
4
  import { SessionHandler } from "../../session/session-handler";
5
- export declare class BasicStrategy<TContext extends BasicContext = BasicContext, TUser = unknown> extends CredentialAuthStrategy<TContext, TUser> {
5
+ import { JwtStrategy } from "../jwt/jwt.strategy";
6
+ export declare class BasicStrategy<TContext = unknown, TUser = unknown> extends CredentialAuthStrategy<TContext, TUser> {
6
7
  protected config: BasicStrategyConfig<TContext, TUser>;
7
8
  protected session?: SessionHandler;
9
+ protected jwt?: JwtStrategy<TContext, TUser>;
8
10
  protected logger?: Soap.Logger;
9
- constructor(config: BasicStrategyConfig<TContext, TUser>, session?: SessionHandler, logger?: Soap.Logger);
11
+ constructor(config: BasicStrategyConfig<TContext, TUser>, session?: SessionHandler, jwt?: JwtStrategy<TContext, TUser>, logger?: Soap.Logger);
10
12
  protected extractCredentials(context?: TContext): {
11
13
  identifier: string;
12
14
  password: string;
13
15
  };
14
16
  protected verifyCredentials(identifier: string, password: string): Promise<boolean>;
15
- protected retrieveUser(credentials: {
16
- identifier: string;
17
- password: string;
18
- }): Promise<TUser | null>;
19
17
  }
@@ -3,18 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BasicStrategy = void 0;
4
4
  const credential_auth_strategy_1 = require("../credential-auth.strategy");
5
5
  const errors_1 = require("../../errors");
6
+ const basic_tools_1 = require("./basic.tools");
6
7
  class BasicStrategy extends credential_auth_strategy_1.CredentialAuthStrategy {
7
8
  config;
8
9
  session;
10
+ jwt;
9
11
  logger;
10
- constructor(config, session, logger) {
11
- super(config, session, logger);
12
+ constructor(config, session, jwt, logger) {
13
+ super((0, basic_tools_1.prepareBasicConfig)(config), session, jwt, logger);
12
14
  this.config = config;
13
15
  this.session = session;
16
+ this.jwt = jwt;
14
17
  this.logger = logger;
15
18
  }
16
19
  extractCredentials(context) {
17
- const authHeader = this.config.credentials.extractCredentials
20
+ const authHeader = this.config.credentials?.extractCredentials
18
21
  ? this.config.credentials.extractCredentials(context)
19
22
  : context?.headers?.authorization ||
20
23
  context?.headers?.["x-custom-auth"] ||
@@ -41,8 +44,5 @@ class BasicStrategy extends credential_auth_strategy_1.CredentialAuthStrategy {
41
44
  async verifyCredentials(identifier, password) {
42
45
  return this.config.credentials.verifyCredentials(identifier, password);
43
46
  }
44
- async retrieveUser(credentials) {
45
- return this.config.user.getUserData(credentials.identifier);
46
- }
47
47
  }
48
48
  exports.BasicStrategy = BasicStrategy;
@@ -0,0 +1,2 @@
1
+ import { BasicStrategyConfig } from "./basic.types";
2
+ export declare const prepareBasicConfig: <TContext = any, TUser = any>(config: BasicStrategyConfig<TContext, TUser>) => BasicStrategyConfig<TContext, TUser>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.prepareBasicConfig = void 0;
27
+ const Soap = __importStar(require("@soapjs/soap"));
28
+ const prepareBasicConfig = (config) => {
29
+ return Soap.removeUndefinedProperties({
30
+ ...config,
31
+ routes: {
32
+ ...config.routes,
33
+ login: {
34
+ path: config.routes.login.path || "/auth/basic/login",
35
+ method: config.routes.login.method || "POST",
36
+ },
37
+ logout: {
38
+ path: config.routes.logout.path || "/auth/basic/logout",
39
+ method: config.routes.logout.method || "POST",
40
+ },
41
+ },
42
+ });
43
+ };
44
+ exports.prepareBasicConfig = prepareBasicConfig;
@@ -2,32 +2,22 @@ import * as Soap from "@soapjs/soap";
2
2
  import { AuthResult, CredentialAuthStrategyConfig } from "../types";
3
3
  import { BaseAuthStrategy } from "./base-auth.strategy";
4
4
  import { SessionHandler } from "../session/session-handler";
5
+ import { JwtStrategy } from "./jwt/jwt.strategy";
6
+ import { PasswordService } from "../services/password.service";
5
7
  export declare abstract class CredentialAuthStrategy<TContext = unknown, TUser = unknown> extends BaseAuthStrategy<TContext, TUser> {
6
8
  protected config: CredentialAuthStrategyConfig<TContext, TUser>;
7
9
  protected session?: SessionHandler;
10
+ protected jwt?: JwtStrategy<TContext, TUser>;
8
11
  protected logger?: Soap.Logger;
12
+ protected password: PasswordService;
9
13
  protected abstract verifyCredentials(identifier: string, password: string): Promise<boolean>;
10
14
  protected abstract extractCredentials(context: TContext): any;
11
- protected abstract retrieveUser(credentials: any): Promise<TUser | null>;
12
- constructor(config: CredentialAuthStrategyConfig<TContext, TUser>, session?: SessionHandler, logger?: Soap.Logger);
13
- protected storeUserSession(user: TUser, context: TContext): Promise<void>;
14
- protected handleAuthenticationError(error: Error, context: TContext): Promise<never>;
15
- protected preAuthChecks(identifier: string): Promise<void>;
16
- protected handleFailedLogin(identifier: string): Promise<void>;
17
- protected handleSuccessfulLogin(identifier: string): Promise<void>;
18
- protected finalizeAuthentication(user: TUser, context: TContext): Promise<void>;
15
+ constructor(config: CredentialAuthStrategyConfig<TContext, TUser>, session?: SessionHandler, jwt?: JwtStrategy<TContext, TUser>, logger?: Soap.Logger);
16
+ protected fetchUser(payload: unknown): Promise<TUser | null>;
19
17
  authenticate(context: TContext): Promise<AuthResult<TUser>>;
20
- protected handleSession(user: TUser, context?: TContext): Promise<void>;
18
+ login(context: TContext): Promise<AuthResult<TUser>>;
21
19
  logout(context: TContext): Promise<void>;
22
20
  requestPasswordReset(identifier: string, email?: string): Promise<void>;
23
21
  resetPassword(identifier: string, token: string, newPassword: string): Promise<void>;
24
22
  changePassword(identifier: string, oldPassword: string, newPassword: string): Promise<void>;
25
- protected auditLoginAttempt(identifier: string, success: boolean, context?: TContext): Promise<void>;
26
- protected auditPasswordChange(identifier: string, context?: TContext): Promise<void>;
27
- protected validatePasswordPolicy(password: string): boolean;
28
- protected checkFailedAttempts(identifier: string): Promise<void>;
29
- protected isAccountLocked(account: any): Promise<boolean>;
30
- protected incrementFailedAttempts(account: any): Promise<void>;
31
- protected notifyAccountLocked(identifier: string): Promise<void>;
32
- protected checkPasswordExpiry(identifier: string): Promise<void>;
33
23
  }