@soapjs/soap-auth 0.1.0 → 0.2.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/README.md +475 -8
- package/build/factories/http-auth-strategy.factory.js +1 -2
- package/build/factories/index.d.ts +3 -0
- package/build/factories/index.js +19 -0
- package/build/index.d.ts +4 -25
- package/build/index.js +4 -25
- package/build/session/index.d.ts +3 -0
- package/build/session/index.js +19 -0
- package/build/soap-auth.d.ts +9 -9
- package/build/soap-auth.js +64 -34
- package/build/strategies/api-key/api-key.strategy.d.ts +4 -3
- package/build/strategies/api-key/api-key.strategy.js +9 -6
- package/build/strategies/api-key/api-key.types.d.ts +2 -4
- package/build/strategies/base-auth.strategy.d.ts +4 -3
- package/build/strategies/base-auth.strategy.js +22 -6
- package/build/strategies/basic/basic.strategy.d.ts +5 -11
- package/build/strategies/basic/basic.strategy.js +14 -19
- package/build/strategies/basic/basic.types.d.ts +2 -2
- package/build/strategies/{credential-based-auth.strategy.d.ts → credential-auth.strategy.d.ts} +15 -12
- package/build/strategies/{credential-based-auth.strategy.js → credential-auth.strategy.js} +95 -46
- package/build/strategies/index.d.ts +16 -0
- package/build/strategies/index.js +32 -0
- package/build/strategies/jwt/jwt.strategy.d.ts +17 -2
- package/build/strategies/jwt/jwt.strategy.js +118 -45
- package/build/strategies/jwt/jwt.tools.d.ts +7 -3
- package/build/strategies/jwt/jwt.tools.js +80 -41
- package/build/strategies/jwt/jwt.types.d.ts +4 -14
- package/build/strategies/local/local.strategy.d.ts +3 -9
- package/build/strategies/local/local.strategy.js +7 -58
- package/build/strategies/local/local.types.d.ts +2 -2
- package/build/strategies/oauth2/oauth2.strategy.d.ts +21 -7
- package/build/strategies/oauth2/oauth2.strategy.js +161 -52
- package/build/strategies/oauth2/oauth2.types.d.ts +9 -17
- package/build/strategies/token-auth.strategy.d.ts +25 -0
- package/build/strategies/token-auth.strategy.js +78 -0
- package/build/tools/index.d.ts +3 -0
- package/build/tools/index.js +19 -0
- package/build/types.d.ts +94 -68
- package/package.json +3 -3
- package/build/strategies/token-based-auth.strategy.d.ts +0 -25
- package/build/strategies/token-based-auth.strategy.js +0 -124
package/build/soap-auth.js
CHANGED
|
@@ -5,71 +5,101 @@ const http_auth_strategy_factory_1 = require("./factories/http-auth-strategy.fac
|
|
|
5
5
|
const socket_auth_strategy_factory_1 = require("./factories/socket-auth-strategy.factory");
|
|
6
6
|
class SoapAuth {
|
|
7
7
|
requiredStrategyMethods = ["authenticate", "init"];
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
strategies = new Map();
|
|
9
|
+
logger;
|
|
10
10
|
constructor(config) {
|
|
11
11
|
const httpFactory = new http_auth_strategy_factory_1.HttpAuthStrategyFactory(config.logger);
|
|
12
|
-
this.httpStrategies = httpFactory.createStrategies(config);
|
|
13
12
|
const socketFactory = new socket_auth_strategy_factory_1.SocketAuthStrategyFactory(config.logger);
|
|
14
|
-
|
|
13
|
+
const httpStrategies = httpFactory.createStrategies(config);
|
|
14
|
+
const socketStrategies = socketFactory.createStrategies(config);
|
|
15
|
+
this.strategies.set("http", httpStrategies);
|
|
16
|
+
this.strategies.set("socket", socketStrategies);
|
|
17
|
+
this.logger = config.logger;
|
|
15
18
|
}
|
|
16
19
|
isAuthStrategy(strategy) {
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
return (typeof strategy === "object" &&
|
|
21
|
+
strategy !== null &&
|
|
22
|
+
this.requiredStrategyMethods.every((method) => typeof strategy[method] === "function"));
|
|
19
23
|
}
|
|
20
|
-
addStrategy(
|
|
24
|
+
addStrategy(strategyInstance, name, type) {
|
|
25
|
+
if (!this.strategies.has(type)) {
|
|
26
|
+
throw new Error(`Invalid strategy type "${type}". Expected "http" or "socket".`);
|
|
27
|
+
}
|
|
21
28
|
if (this.isAuthStrategy(strategyInstance)) {
|
|
22
|
-
|
|
29
|
+
this.strategies.get(type).set(name, strategyInstance);
|
|
23
30
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.httpStrategies.delete(type);
|
|
28
|
-
return true;
|
|
31
|
+
else {
|
|
32
|
+
this.logger?.error("Invalid authentication strategy provided.");
|
|
33
|
+
throw new Error("Invalid authentication strategy: does not implement required methods.");
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
}
|
|
36
|
+
removeStrategy(name, type) {
|
|
37
|
+
if (!this.strategies.has(type)) {
|
|
38
|
+
throw new Error(`Invalid strategy type "${type}". Expected "http" or "socket".`);
|
|
33
39
|
}
|
|
34
|
-
|
|
40
|
+
const names = Array.isArray(name) ? name : [name];
|
|
41
|
+
names.forEach((n) => {
|
|
42
|
+
this.strategies.get(type).delete(n);
|
|
43
|
+
});
|
|
35
44
|
}
|
|
36
|
-
hasStrategy(type) {
|
|
37
|
-
|
|
45
|
+
hasStrategy(name, type) {
|
|
46
|
+
if (!this.strategies.has(type)) {
|
|
47
|
+
throw new Error(`Invalid strategy type "${type}". Expected "http" or "socket".`);
|
|
48
|
+
}
|
|
49
|
+
return this.strategies.get(type).has(name);
|
|
38
50
|
}
|
|
39
|
-
getStrategy(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
getStrategy(name, type) {
|
|
52
|
+
if (!this.strategies.has(type)) {
|
|
53
|
+
throw new Error(`Invalid strategy type "${type}". Expected "http" or "socket".`);
|
|
54
|
+
}
|
|
55
|
+
const strategy = this.strategies.get(type).get(name);
|
|
56
|
+
if (!strategy) {
|
|
57
|
+
throw new Error(`Authentication strategy "${name}" not found.`);
|
|
58
|
+
}
|
|
59
|
+
return strategy;
|
|
43
60
|
}
|
|
44
|
-
listStrategies() {
|
|
45
|
-
|
|
61
|
+
listStrategies(type) {
|
|
62
|
+
if (!this.strategies.has(type)) {
|
|
63
|
+
throw new Error(`Invalid strategy type "${type}". Expected "http" or "socket".`);
|
|
64
|
+
}
|
|
65
|
+
return Array.from(this.strategies.get(type).keys());
|
|
46
66
|
}
|
|
47
67
|
async init(sequential = false) {
|
|
48
68
|
const strategies = [
|
|
49
|
-
...this.
|
|
50
|
-
...this.
|
|
69
|
+
...this.strategies.get("http").values(),
|
|
70
|
+
...this.strategies.get("socket").values(),
|
|
51
71
|
];
|
|
52
72
|
if (sequential) {
|
|
53
73
|
for (const strategy of strategies) {
|
|
54
|
-
|
|
74
|
+
try {
|
|
75
|
+
await strategy.init();
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.logger?.error(`Failed to initialize strategy: ${error.message}`);
|
|
79
|
+
}
|
|
55
80
|
}
|
|
56
81
|
}
|
|
57
82
|
else {
|
|
58
|
-
await Promise.all(strategies.map((strategy) => strategy
|
|
83
|
+
await Promise.all(strategies.map((strategy) => strategy
|
|
84
|
+
.init()
|
|
85
|
+
.catch((error) => this.logger?.error(`Failed to initialize strategy: ${error.message}`))));
|
|
59
86
|
}
|
|
60
87
|
}
|
|
61
|
-
async authenticate(
|
|
62
|
-
const strategy = this.getStrategy(
|
|
88
|
+
async authenticate(type, name, context) {
|
|
89
|
+
const strategy = this.getStrategy(name, type);
|
|
63
90
|
if (!strategy) {
|
|
64
|
-
throw new Error(`Authentication strategy "${
|
|
91
|
+
throw new Error(`Authentication strategy "${name}" not found.`);
|
|
65
92
|
}
|
|
66
93
|
return strategy.authenticate(context);
|
|
67
94
|
}
|
|
68
|
-
async logout(
|
|
69
|
-
const strategy = this.getStrategy(
|
|
95
|
+
async logout(type, name, context) {
|
|
96
|
+
const strategy = this.getStrategy(name, type);
|
|
70
97
|
if (strategy?.logout) {
|
|
71
98
|
await strategy.logout(context);
|
|
72
99
|
}
|
|
100
|
+
else {
|
|
101
|
+
this.logger?.error(`No "logout" implementation in strategy "${name}".`);
|
|
102
|
+
}
|
|
73
103
|
}
|
|
74
104
|
}
|
|
75
105
|
exports.SoapAuth = SoapAuth;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as Soap from "@soapjs/soap";
|
|
2
2
|
import { AuthResult, AuthStrategy } from "../../types";
|
|
3
3
|
import { ApiKeyStrategyConfig } from "./api-key.types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { BaseAuthStrategy } from "../base-auth.strategy";
|
|
5
|
+
export declare class ApiKeyStrategy<TContext = unknown, TUser = unknown> extends BaseAuthStrategy<TContext, TUser> implements AuthStrategy<TContext, TUser> {
|
|
6
|
+
protected config: ApiKeyStrategyConfig<TContext, TUser>;
|
|
7
7
|
constructor(config: ApiKeyStrategyConfig<TContext, TUser>, logger: Soap.Logger);
|
|
8
8
|
init(): Promise<void>;
|
|
9
9
|
authenticate(context?: TContext): Promise<AuthResult<TUser>>;
|
|
@@ -11,4 +11,5 @@ export declare class ApiKeyStrategy<TContext = unknown, TUser = unknown> impleme
|
|
|
11
11
|
revoke(apiKey: string): Promise<void>;
|
|
12
12
|
private trackApiKeyUsage;
|
|
13
13
|
private incrementRequestCount;
|
|
14
|
+
logout(context: TContext): Promise<void>;
|
|
14
15
|
}
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ApiKeyStrategy = void 0;
|
|
4
4
|
const api_key_errors_1 = require("./api-key.errors");
|
|
5
5
|
const errors_1 = require("../../errors");
|
|
6
|
-
|
|
6
|
+
const base_auth_strategy_1 = require("../base-auth.strategy");
|
|
7
|
+
class ApiKeyStrategy extends base_auth_strategy_1.BaseAuthStrategy {
|
|
7
8
|
config;
|
|
8
|
-
logger;
|
|
9
9
|
constructor(config, logger) {
|
|
10
|
+
super(config, null, logger);
|
|
10
11
|
this.config = config;
|
|
11
|
-
this.logger = logger;
|
|
12
12
|
if (!this.config.extractApiKey || !this.config.retrieveUserByApiKey) {
|
|
13
13
|
throw new Error("ApiKeyStrategy requires extractApiKey and retrieveUserByApiKey functions.");
|
|
14
14
|
}
|
|
@@ -45,13 +45,13 @@ class ApiKeyStrategy {
|
|
|
45
45
|
}
|
|
46
46
|
await this.trackApiKeyUsage(apiKey);
|
|
47
47
|
await this.incrementRequestCount(apiKey);
|
|
48
|
-
await this.
|
|
48
|
+
await this.onSuccess("authenticate", { user, context });
|
|
49
49
|
return { user };
|
|
50
50
|
}
|
|
51
51
|
catch (error) {
|
|
52
52
|
this.logger.error("API Key authentication error:", error);
|
|
53
53
|
try {
|
|
54
|
-
await this.
|
|
54
|
+
await this.onFailure("authenticate", { error, context });
|
|
55
55
|
}
|
|
56
56
|
catch (callbackError) {
|
|
57
57
|
this.logger.error("onFailure callback error during authentication:", callbackError);
|
|
@@ -63,7 +63,7 @@ class ApiKeyStrategy {
|
|
|
63
63
|
if (this.config.authorize) {
|
|
64
64
|
return this.config.authorize(user, action, resource);
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
return true;
|
|
67
67
|
}
|
|
68
68
|
async revoke(apiKey) {
|
|
69
69
|
if (this.config.revokeApiKey) {
|
|
@@ -91,5 +91,8 @@ class ApiKeyStrategy {
|
|
|
91
91
|
this.logger.warn("Failed to increment request count:", error);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
+
logout(context) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
94
97
|
}
|
|
95
98
|
exports.ApiKeyStrategy = ApiKeyStrategy;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { RateLimitConfig, RoleAuthorizationConfig,
|
|
2
|
-
export interface ApiKeyStrategyConfig<TContext = unknown, TUser = unknown> extends ApiKeyTrackingConfig, RateLimitConfig, RoleAuthorizationConfig<TUser>, AccountLockConfig<TContext> {
|
|
1
|
+
import { RateLimitConfig, RoleAuthorizationConfig, AccountLockConfig, AuthResultConfig } from "../../types";
|
|
2
|
+
export interface ApiKeyStrategyConfig<TContext = unknown, TUser = unknown> extends AuthResultConfig<TContext, TUser>, ApiKeyTrackingConfig, RateLimitConfig, RoleAuthorizationConfig<TUser>, AccountLockConfig<TContext> {
|
|
3
3
|
extractApiKey: (context: TContext) => string | null;
|
|
4
4
|
retrieveUserByApiKey: (apiKey: string) => Promise<TUser | null>;
|
|
5
5
|
authorize?: (user: TUser, action: string, resource?: string) => Promise<boolean>;
|
|
6
6
|
revokeApiKey?: (apiKey: string) => Promise<void>;
|
|
7
|
-
onSuccess?: (context: AuthSuccessContext<TUser, TContext>) => Promise<void> | void;
|
|
8
|
-
onFailure?: (context: AuthFailureContext<TContext>) => Promise<void> | void;
|
|
9
7
|
}
|
|
10
8
|
export interface ApiKeyTrackingConfig {
|
|
11
9
|
trackApiKeyUsage?: (apiKey: string) => Promise<void>;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import * as Soap from "@soapjs/soap";
|
|
2
|
-
import { AuthResult, AuthStrategy, BaseAuthStrategyConfig } from "../types";
|
|
2
|
+
import { AuthFailureContext, AuthResult, AuthStrategy, AuthSuccessContext, BaseAuthStrategyConfig } from "../types";
|
|
3
3
|
import { SessionHandler } from "../session/session-handler";
|
|
4
4
|
export declare abstract class BaseAuthStrategy<TContext = unknown, TUser = unknown> implements AuthStrategy<TContext, TUser> {
|
|
5
5
|
protected config: BaseAuthStrategyConfig<TContext, TUser>;
|
|
6
6
|
protected session?: SessionHandler;
|
|
7
7
|
protected logger?: Soap.Logger;
|
|
8
8
|
abstract authenticate(context?: TContext): Promise<AuthResult<TUser>>;
|
|
9
|
-
protected abstract retrieveUser(context: TContext): Promise<TUser | null>;
|
|
10
9
|
abstract logout(context: TContext): Promise<void>;
|
|
11
10
|
constructor(config: BaseAuthStrategyConfig<TContext, TUser>, session?: SessionHandler, logger?: Soap.Logger);
|
|
12
11
|
init(): Promise<void>;
|
|
13
|
-
protected isAccountLocked(account: any
|
|
12
|
+
protected isAccountLocked(account: any): Promise<boolean>;
|
|
14
13
|
protected isAuthorized(user: TUser): Promise<boolean>;
|
|
15
14
|
protected checkRateLimit(data: unknown): Promise<void>;
|
|
16
15
|
protected checkMfa(user: TUser, context: TContext): Promise<void>;
|
|
16
|
+
protected onSuccess(action: string, context: AuthSuccessContext<TUser, TContext>): Promise<void>;
|
|
17
|
+
protected onFailure(action: string, context: AuthFailureContext<TContext>): Promise<void>;
|
|
17
18
|
}
|
|
@@ -14,15 +14,15 @@ class BaseAuthStrategy {
|
|
|
14
14
|
async init() {
|
|
15
15
|
return Promise.resolve();
|
|
16
16
|
}
|
|
17
|
-
async isAccountLocked(account
|
|
18
|
-
if (await this.config.isAccountLocked?.(account
|
|
17
|
+
async isAccountLocked(account) {
|
|
18
|
+
if (await this.config.lock.isAccountLocked?.(account)) {
|
|
19
19
|
throw new errors_1.AccountLockedError();
|
|
20
20
|
}
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
async isAuthorized(user) {
|
|
24
|
-
if (this.config.authorizeByRoles && this.config.roles) {
|
|
25
|
-
const hasAccess = await this.config.authorizeByRoles(user, this.config.roles);
|
|
24
|
+
if (this.config.role.authorizeByRoles && this.config.role.roles) {
|
|
25
|
+
const hasAccess = await this.config.role.authorizeByRoles(user, this.config.role.roles);
|
|
26
26
|
if (!hasAccess) {
|
|
27
27
|
throw new errors_1.UnauthorizedRoleError();
|
|
28
28
|
}
|
|
@@ -30,8 +30,8 @@ class BaseAuthStrategy {
|
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
32
|
async checkRateLimit(data) {
|
|
33
|
-
if (this.config.checkRateLimit &&
|
|
34
|
-
(await this.config.checkRateLimit(data))) {
|
|
33
|
+
if (this.config.rateLimit.checkRateLimit &&
|
|
34
|
+
(await this.config.rateLimit.checkRateLimit(data))) {
|
|
35
35
|
throw new errors_1.RateLimitExceededError();
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -65,5 +65,21 @@ class BaseAuthStrategy {
|
|
|
65
65
|
throw error;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
async onSuccess(action, context) {
|
|
69
|
+
try {
|
|
70
|
+
await this.config.onSuccess?.(action, context);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
this.logger?.error(error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async onFailure(action, context) {
|
|
77
|
+
try {
|
|
78
|
+
await this.config.onFailure?.(action, context);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
this.logger?.error(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
68
84
|
}
|
|
69
85
|
exports.BaseAuthStrategy = BaseAuthStrategy;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import * as Soap from "@soapjs/soap";
|
|
2
|
-
import {
|
|
2
|
+
import { CredentialAuthStrategy } from "../credential-auth.strategy";
|
|
3
3
|
import { BasicContext, BasicStrategyConfig } from "./basic.types";
|
|
4
4
|
import { SessionHandler } from "../../session/session-handler";
|
|
5
|
-
export declare class BasicStrategy<TContext extends BasicContext = BasicContext, TUser = unknown> extends
|
|
5
|
+
export declare class BasicStrategy<TContext extends BasicContext = BasicContext, TUser = unknown> extends CredentialAuthStrategy<TContext, TUser> {
|
|
6
6
|
protected config: BasicStrategyConfig<TContext, TUser>;
|
|
7
7
|
protected session?: SessionHandler;
|
|
8
8
|
protected logger?: Soap.Logger;
|
|
9
9
|
constructor(config: BasicStrategyConfig<TContext, TUser>, session?: SessionHandler, logger?: Soap.Logger);
|
|
10
|
-
protected extractCredentials(context?: TContext):
|
|
10
|
+
protected extractCredentials(context?: TContext): {
|
|
11
11
|
identifier: string;
|
|
12
12
|
password: string;
|
|
13
|
-
}
|
|
14
|
-
protected verifyCredentials(
|
|
15
|
-
identifier: string;
|
|
16
|
-
password: string;
|
|
17
|
-
}): Promise<boolean>;
|
|
13
|
+
};
|
|
14
|
+
protected verifyCredentials(identifier: string, password: string): Promise<boolean>;
|
|
18
15
|
protected retrieveUser(credentials: {
|
|
19
16
|
identifier: string;
|
|
20
17
|
password: string;
|
|
21
18
|
}): Promise<TUser | null>;
|
|
22
|
-
requestPasswordReset(email: string): Promise<void>;
|
|
23
|
-
resetPassword(email: string, token: string, newPassword: string): Promise<void>;
|
|
24
|
-
changePassword(email: string, oldPassword: string, newPassword: string): Promise<void>;
|
|
25
19
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BasicStrategy = void 0;
|
|
4
|
-
const
|
|
4
|
+
const credential_auth_strategy_1 = require("../credential-auth.strategy");
|
|
5
5
|
const errors_1 = require("../../errors");
|
|
6
|
-
class BasicStrategy extends
|
|
6
|
+
class BasicStrategy extends credential_auth_strategy_1.CredentialAuthStrategy {
|
|
7
7
|
config;
|
|
8
8
|
session;
|
|
9
9
|
logger;
|
|
@@ -13,17 +13,21 @@ class BasicStrategy extends credential_based_auth_strategy_1.CredentialBasedAuth
|
|
|
13
13
|
this.session = session;
|
|
14
14
|
this.logger = logger;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
const authHeader =
|
|
16
|
+
extractCredentials(context) {
|
|
17
|
+
const authHeader = this.config.credentials.extractCredentials
|
|
18
|
+
? this.config.credentials.extractCredentials(context)
|
|
19
|
+
: context?.headers?.authorization ||
|
|
20
|
+
context?.headers?.["x-custom-auth"] ||
|
|
21
|
+
context?.headers?.["proxy-authorization"];
|
|
18
22
|
if (!authHeader) {
|
|
19
23
|
throw new errors_1.MissingCredentialsError();
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
if (parts.length !== 2 || parts[0] !== "Basic") {
|
|
25
|
+
if (!authHeader || !authHeader.toLowerCase().startsWith("basic ")) {
|
|
23
26
|
throw new errors_1.InvalidCredentialsError();
|
|
24
27
|
}
|
|
28
|
+
const encoded = authHeader.substring(6);
|
|
25
29
|
try {
|
|
26
|
-
const decoded = Buffer.from(
|
|
30
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
|
|
27
31
|
const [username, password] = decoded.split(":");
|
|
28
32
|
if (!username || !password) {
|
|
29
33
|
throw new errors_1.InvalidCredentialsError();
|
|
@@ -34,20 +38,11 @@ class BasicStrategy extends credential_based_auth_strategy_1.CredentialBasedAuth
|
|
|
34
38
|
throw new errors_1.InvalidCredentialsError();
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
|
-
async verifyCredentials(
|
|
38
|
-
return this.config.
|
|
41
|
+
async verifyCredentials(identifier, password) {
|
|
42
|
+
return this.config.credentials.verifyCredentials(identifier, password);
|
|
39
43
|
}
|
|
40
44
|
async retrieveUser(credentials) {
|
|
41
|
-
return this.config.
|
|
42
|
-
}
|
|
43
|
-
async requestPasswordReset(email) {
|
|
44
|
-
await super.requestPasswordReset(email);
|
|
45
|
-
}
|
|
46
|
-
async resetPassword(email, token, newPassword) {
|
|
47
|
-
await super.resetPassword(email, token, newPassword);
|
|
48
|
-
}
|
|
49
|
-
async changePassword(email, oldPassword, newPassword) {
|
|
50
|
-
await super.changePassword(email, oldPassword, newPassword);
|
|
45
|
+
return this.config.user.getUserData(credentials.identifier);
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
48
|
exports.BasicStrategy = BasicStrategy;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface BasicStrategyConfig<TContext = unknown, TUser = unknown> extends
|
|
1
|
+
import { CredentialAuthStrategyConfig } from "../../types";
|
|
2
|
+
export interface BasicStrategyConfig<TContext = unknown, TUser = unknown> extends CredentialAuthStrategyConfig<TContext, TUser> {
|
|
3
3
|
}
|
|
4
4
|
export type BasicContext = {
|
|
5
5
|
headers: {
|
package/build/strategies/{credential-based-auth.strategy.d.ts → credential-auth.strategy.d.ts}
RENAMED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import * as Soap from "@soapjs/soap";
|
|
2
|
-
import { AuthResult,
|
|
2
|
+
import { AuthResult, CredentialAuthStrategyConfig } from "../types";
|
|
3
3
|
import { BaseAuthStrategy } from "./base-auth.strategy";
|
|
4
4
|
import { SessionHandler } from "../session/session-handler";
|
|
5
|
-
export declare abstract class
|
|
6
|
-
protected config:
|
|
5
|
+
export declare abstract class CredentialAuthStrategy<TContext = unknown, TUser = unknown> extends BaseAuthStrategy<TContext, TUser> {
|
|
6
|
+
protected config: CredentialAuthStrategyConfig<TContext, TUser>;
|
|
7
7
|
protected session?: SessionHandler;
|
|
8
8
|
protected logger?: Soap.Logger;
|
|
9
|
-
protected abstract
|
|
10
|
-
|
|
11
|
-
password: string;
|
|
12
|
-
}>;
|
|
13
|
-
protected abstract verifyCredentials(credentials: any): Promise<boolean>;
|
|
9
|
+
protected abstract verifyCredentials(identifier: string, password: string): Promise<boolean>;
|
|
10
|
+
protected abstract extractCredentials(context: TContext): any;
|
|
14
11
|
protected abstract retrieveUser(credentials: any): Promise<TUser | null>;
|
|
15
|
-
constructor(config:
|
|
16
|
-
|
|
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>;
|
|
19
|
+
authenticate(context: TContext): Promise<AuthResult<TUser>>;
|
|
17
20
|
protected handleSession(user: TUser, context?: TContext): Promise<void>;
|
|
18
|
-
logout(context
|
|
21
|
+
logout(context: TContext): Promise<void>;
|
|
19
22
|
requestPasswordReset(identifier: string, email?: string): Promise<void>;
|
|
20
23
|
resetPassword(identifier: string, token: string, newPassword: string): Promise<void>;
|
|
21
24
|
changePassword(identifier: string, oldPassword: string, newPassword: string): Promise<void>;
|
|
@@ -23,7 +26,7 @@ export declare abstract class CredentialBasedAuthStrategy<TContext = unknown, TU
|
|
|
23
26
|
protected auditPasswordChange(identifier: string, context?: TContext): Promise<void>;
|
|
24
27
|
protected validatePasswordPolicy(password: string): boolean;
|
|
25
28
|
protected checkFailedAttempts(identifier: string): Promise<void>;
|
|
26
|
-
protected isAccountLocked(account: any
|
|
29
|
+
protected isAccountLocked(account: any): Promise<boolean>;
|
|
27
30
|
protected incrementFailedAttempts(account: any): Promise<void>;
|
|
28
31
|
protected notifyAccountLocked(identifier: string): Promise<void>;
|
|
29
32
|
protected checkPasswordExpiry(identifier: string): Promise<void>;
|