@3sixty/api-auth-entity-storage-service 0.20.0-next.0 → 0.20.0-next.1
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 +1 -1
- package/dist/es/entities/authenticationUser.js +1 -9
- package/dist/es/entities/authenticationUser.js.map +1 -1
- package/dist/es/entities/authenticationUserV0.js +69 -0
- package/dist/es/entities/authenticationUserV0.js.map +1 -0
- package/dist/es/index.js +1 -9
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IAuthHeaderProcessorConfig.js.map +1 -1
- package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js.map +1 -1
- package/dist/es/models/IAuthTokenContext.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js.map +1 -1
- package/dist/es/processors/authHeaderProcessor.js +9 -14
- package/dist/es/processors/authHeaderProcessor.js.map +1 -1
- package/dist/es/restEntryPoints.js +1 -8
- package/dist/es/restEntryPoints.js.map +1 -1
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js +22 -14
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js.map +1 -1
- package/dist/es/routes/entityStorageAuthenticationRoutes.js +45 -1
- package/dist/es/routes/entityStorageAuthenticationRoutes.js.map +1 -1
- package/dist/es/schema.js +2 -4
- package/dist/es/schema.js.map +1 -1
- package/dist/es/services/entityStorageAuthenticationAdminService.js +69 -68
- package/dist/es/services/entityStorageAuthenticationAdminService.js.map +1 -1
- package/dist/es/services/entityStorageAuthenticationService.js +29 -17
- package/dist/es/services/entityStorageAuthenticationService.js.map +1 -1
- package/dist/es/utils/passwordHelper.js +7 -5
- package/dist/es/utils/passwordHelper.js.map +1 -1
- package/dist/es/utils/tokenHelper.js +2 -23
- package/dist/es/utils/tokenHelper.js.map +1 -1
- package/dist/types/entities/authenticationUser.d.ts +0 -4
- package/dist/types/entities/authenticationUserV0.d.ts +33 -0
- package/dist/types/index.d.ts +1 -9
- package/dist/types/models/IAuthHeaderProcessorConfig.d.ts +1 -2
- package/dist/types/models/IAuthTokenContext.d.ts +0 -4
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConfig.d.ts +14 -3
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +6 -1
- package/dist/types/models/IEntityStorageAuthenticationServiceConfig.d.ts +7 -2
- package/dist/types/restEntryPoints.d.ts +1 -1
- package/dist/types/routes/entityStorageAuthenticationRoutes.d.ts +10 -2
- package/dist/types/services/entityStorageAuthenticationAdminService.d.ts +6 -2
- package/dist/types/services/entityStorageAuthenticationService.d.ts +6 -1
- package/dist/types/utils/passwordHelper.d.ts +6 -3
- package/dist/types/utils/tokenHelper.d.ts +2 -11
- package/docs/changelog.md +19 -0
- package/docs/examples.md +9 -93
- package/docs/open-api/spec.json +178 -956
- package/docs/reference/classes/AuthHeaderProcessor.md +4 -0
- package/docs/reference/classes/AuthenticationUser.md +0 -8
- package/docs/reference/classes/AuthenticationUserV0.md +69 -0
- package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +11 -3
- package/docs/reference/classes/EntityStorageAuthenticationService.md +18 -0
- package/docs/reference/classes/PasswordHelper.md +4 -4
- package/docs/reference/classes/TokenHelper.md +2 -44
- package/docs/reference/functions/authenticationPasswordPolicy.md +31 -0
- package/docs/reference/index.md +2 -15
- package/docs/reference/interfaces/IAuthHeaderProcessorConfig.md +1 -2
- package/docs/reference/interfaces/IAuthTokenContext.md +0 -8
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConfig.md +38 -4
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +15 -1
- package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConfig.md +15 -1
- package/docs/reference/variables/restEntryPoints.md +1 -1
- package/locales/en.json +1 -16
- package/package.json +7 -8
- package/dist/es/entities/authenticationAuditEntry.js +0 -121
- package/dist/es/entities/authenticationAuditEntry.js.map +0 -1
- package/dist/es/entities/authenticationRateEntry.js +0 -37
- package/dist/es/entities/authenticationRateEntry.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js +0 -4
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js +0 -2
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js +0 -2
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js +0 -2
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js.map +0 -1
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js +0 -343
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js.map +0 -1
- package/dist/es/services/entityStorageAuthenticationAuditService.js +0 -240
- package/dist/es/services/entityStorageAuthenticationAuditService.js.map +0 -1
- package/dist/es/services/entityStorageAuthenticationRateService.js +0 -213
- package/dist/es/services/entityStorageAuthenticationRateService.js.map +0 -1
- package/dist/types/entities/authenticationAuditEntry.d.ts +0 -49
- package/dist/types/entities/authenticationRateEntry.d.ts +0 -17
- package/dist/types/models/IEntityStorageAuthenticationAuditServiceConfig.d.ts +0 -9
- package/dist/types/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.d.ts +0 -15
- package/dist/types/models/IEntityStorageAuthenticationRateServiceConfig.d.ts +0 -10
- package/dist/types/models/IEntityStorageAuthenticationRateServiceConstructorOptions.d.ts +0 -25
- package/dist/types/routes/entityStorageAuthenticationAuditRoutes.d.ts +0 -54
- package/dist/types/services/entityStorageAuthenticationAuditService.d.ts +0 -72
- package/dist/types/services/entityStorageAuthenticationRateService.d.ts +0 -60
- package/docs/reference/classes/AuthenticationAuditEntry.md +0 -101
- package/docs/reference/classes/AuthenticationRateEntry.md +0 -37
- package/docs/reference/classes/EntityStorageAuthenticationAuditService.md +0 -241
- package/docs/reference/classes/EntityStorageAuthenticationRateService.md +0 -227
- package/docs/reference/functions/authenticationAuditCreate.md +0 -37
- package/docs/reference/functions/authenticationAuditGet.md +0 -31
- package/docs/reference/functions/authenticationAuditQuery.md +0 -31
- package/docs/reference/functions/authenticationAuditRemove.md +0 -31
- package/docs/reference/functions/authenticationAuditUpdate.md +0 -31
- package/docs/reference/functions/generateRestRoutesAuthenticationAudit.md +0 -25
- package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConfig.md +0 -11
- package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConstructorOptions.md +0 -25
- package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConfig.md +0 -17
- package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConstructorOptions.md +0 -53
- package/docs/reference/variables/tagsAuthenticationAudit.md +0 -5
package/dist/types/index.d.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
export * from "./entities/authenticationAuditEntry.js";
|
|
2
|
-
export * from "./entities/authenticationRateEntry.js";
|
|
3
1
|
export * from "./entities/authenticationUser.js";
|
|
2
|
+
export * from "./entities/authenticationUserV0.js";
|
|
4
3
|
export * from "./models/IAuthHeaderProcessorConfig.js";
|
|
5
4
|
export * from "./models/IAuthHeaderProcessorConstructorOptions.js";
|
|
6
5
|
export * from "./models/IAuthTokenContext.js";
|
|
7
6
|
export * from "./models/IEntityStorageAuthenticationAdminServiceConfig.js";
|
|
8
7
|
export * from "./models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js";
|
|
9
|
-
export * from "./models/IEntityStorageAuthenticationAuditServiceConfig.js";
|
|
10
|
-
export * from "./models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js";
|
|
11
|
-
export * from "./models/IEntityStorageAuthenticationRateServiceConfig.js";
|
|
12
|
-
export * from "./models/IEntityStorageAuthenticationRateServiceConstructorOptions.js";
|
|
13
8
|
export * from "./models/IEntityStorageAuthenticationServiceConfig.js";
|
|
14
9
|
export * from "./models/IEntityStorageAuthenticationServiceConstructorOptions.js";
|
|
15
10
|
export * from "./processors/authHeaderProcessor.js";
|
|
16
11
|
export * from "./restEntryPoints.js";
|
|
17
12
|
export * from "./routes/entityStorageAuthenticationAdminRoutes.js";
|
|
18
|
-
export * from "./routes/entityStorageAuthenticationAuditRoutes.js";
|
|
19
13
|
export * from "./routes/entityStorageAuthenticationRoutes.js";
|
|
20
14
|
export * from "./schema.js";
|
|
21
15
|
export * from "./services/entityStorageAuthenticationAdminService.js";
|
|
22
|
-
export * from "./services/entityStorageAuthenticationAuditService.js";
|
|
23
|
-
export * from "./services/entityStorageAuthenticationRateService.js";
|
|
24
16
|
export * from "./services/entityStorageAuthenticationService.js";
|
|
25
17
|
export * from "./utils/tokenHelper.js";
|
|
26
18
|
export * from "./utils/passwordHelper.js";
|
|
@@ -21,8 +21,7 @@ export interface IAuthHeaderProcessorConfig {
|
|
|
21
21
|
* was verified and not extended by use, set to 0 to disable caching. A hit skips the vault
|
|
22
22
|
* signature check, the tenant lookup and the user lookup, so this is also the longest a password
|
|
23
23
|
* change, a user removal or a signing key rotation can go unnoticed. An entry never outlives the
|
|
24
|
-
* expiry claim of its own token either.
|
|
25
|
-
* request.
|
|
24
|
+
* expiry claim of its own token either.
|
|
26
25
|
* @default 30000
|
|
27
26
|
*/
|
|
28
27
|
tokenCacheTtlMs?: number;
|
|
@@ -23,10 +23,6 @@ export interface IAuthTokenContext {
|
|
|
23
23
|
* The organization of the verified user.
|
|
24
24
|
*/
|
|
25
25
|
userOrganization?: string;
|
|
26
|
-
/**
|
|
27
|
-
* The comma separated scopes carried by the token.
|
|
28
|
-
*/
|
|
29
|
-
scope?: string;
|
|
30
26
|
/**
|
|
31
27
|
* The expiry of the token in milliseconds since the epoch, if it carried one.
|
|
32
28
|
*/
|
|
@@ -4,11 +4,22 @@
|
|
|
4
4
|
export interface IEntityStorageAuthenticationAdminServiceConfig {
|
|
5
5
|
/**
|
|
6
6
|
* The minimum password length.
|
|
7
|
-
* @default
|
|
7
|
+
* @default 15
|
|
8
8
|
*/
|
|
9
9
|
minPasswordLength?: number;
|
|
10
10
|
/**
|
|
11
|
-
* The
|
|
11
|
+
* The maximum password length.
|
|
12
|
+
* @default 128
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
maxPasswordLength?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The role that grants escalated privilege, only callers holding it can modify accounts that hold it.
|
|
17
|
+
* @default global-admin
|
|
18
|
+
*/
|
|
19
|
+
escalatedPrivilegeRole?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The authorization model ID used to look up roles.
|
|
22
|
+
* @default system
|
|
23
|
+
*/
|
|
24
|
+
authorizationModelId?: string;
|
|
14
25
|
}
|
|
@@ -9,10 +9,15 @@ export interface IEntityStorageAuthenticationAdminServiceConstructorOptions {
|
|
|
9
9
|
*/
|
|
10
10
|
userEntityStorageType?: string;
|
|
11
11
|
/**
|
|
12
|
-
* The audit
|
|
12
|
+
* The audit component.
|
|
13
13
|
* @default authentication-audit
|
|
14
14
|
*/
|
|
15
15
|
authenticationAuditServiceType?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The authorization component used to guard accounts with escalated privilege.
|
|
18
|
+
* @default authorization
|
|
19
|
+
*/
|
|
20
|
+
authorizationComponentType?: string;
|
|
16
21
|
/**
|
|
17
22
|
* The configuration for the authentication.
|
|
18
23
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IAuthenticationRateActionConfig } from "@3sixty/api-auth-
|
|
1
|
+
import type { IAuthenticationRateActionConfig } from "@3sixty/api-auth-models";
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for the entity storage authentication service.
|
|
4
4
|
*/
|
|
@@ -15,9 +15,14 @@ export interface IEntityStorageAuthenticationServiceConfig {
|
|
|
15
15
|
defaultTtlMinutes?: number;
|
|
16
16
|
/**
|
|
17
17
|
* The minimum password length for new password validation.
|
|
18
|
-
* @default
|
|
18
|
+
* @default 15
|
|
19
19
|
*/
|
|
20
20
|
minPasswordLength?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The maximum password length for new password validation.
|
|
23
|
+
* @default 128
|
|
24
|
+
*/
|
|
25
|
+
maxPasswordLength?: number;
|
|
21
26
|
/**
|
|
22
27
|
* Optional override for login failure rate limit.
|
|
23
28
|
* @default { maxAttempts: 5, windowMinutes: 15 }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IRestRouteEntryPoint } from "@3sixty/api-models";
|
|
2
2
|
/**
|
|
3
|
-
* REST entry points for the authentication
|
|
3
|
+
* REST entry points for the authentication and authentication admin services.
|
|
4
4
|
*/
|
|
5
5
|
export declare const restEntryPoints: IRestRouteEntryPoint[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ILoginRequest, ILoginResponse, ILogoutRequest, IRefreshTokenRequest, IRefreshTokenResponse, IUpdatePasswordRequest } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
-
import type { IHttpRequestContext, INoContentResponse, IRestRoute, IRestRouteResponseOptions, ITag } from "@3sixty/api-models";
|
|
1
|
+
import type { ILoginRequest, ILoginResponse, ILogoutRequest, IPasswordPolicyResponse, IRefreshTokenRequest, IRefreshTokenResponse, IUpdatePasswordRequest } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
+
import type { IHttpRequestContext, INoContentRequest, INoContentResponse, IRestRoute, IRestRouteResponseOptions, ITag } from "@3sixty/api-models";
|
|
3
3
|
/**
|
|
4
4
|
* The tag to associate with the routes.
|
|
5
5
|
*/
|
|
@@ -43,3 +43,11 @@ export declare function authenticationRefreshToken(httpRequestContext: IHttpRequ
|
|
|
43
43
|
* @returns The response object with additional http response properties.
|
|
44
44
|
*/
|
|
45
45
|
export declare function authenticationUpdatePassword(httpRequestContext: IHttpRequestContext, componentName: string, request: IUpdatePasswordRequest): Promise<INoContentResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the password policy.
|
|
48
|
+
* @param httpRequestContext The request context for the API.
|
|
49
|
+
* @param componentName The name of the component to use in the routes.
|
|
50
|
+
* @param request The request.
|
|
51
|
+
* @returns The response object with additional http response properties.
|
|
52
|
+
*/
|
|
53
|
+
export declare function authenticationPasswordPolicy(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IPasswordPolicyResponse & IRestRouteResponseOptions>;
|
|
@@ -9,9 +9,13 @@ export declare class EntityStorageAuthenticationAdminService implements IAuthent
|
|
|
9
9
|
*/
|
|
10
10
|
static readonly CLASS_NAME: string;
|
|
11
11
|
/**
|
|
12
|
-
* The
|
|
12
|
+
* The default role that grants escalated privilege.
|
|
13
13
|
*/
|
|
14
|
-
static readonly
|
|
14
|
+
static readonly DEFAULT_ESCALATED_PRIVILEGE_ROLE: string;
|
|
15
|
+
/**
|
|
16
|
+
* The default authorization model ID used to look up roles.
|
|
17
|
+
*/
|
|
18
|
+
static readonly DEFAULT_AUTHORIZATION_MODEL_ID: string;
|
|
15
19
|
/**
|
|
16
20
|
* Create a new instance of EntityStorageAuthentication.
|
|
17
21
|
* @param options The dependencies for the identity connector.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IAuthenticationComponent } from "@3sixty/api-auth-entity-storage-models";
|
|
1
|
+
import type { IAuthenticationComponent, IPasswordOptions } from "@3sixty/api-auth-entity-storage-models";
|
|
2
2
|
import type { IEntityStorageAuthenticationServiceConstructorOptions } from "../models/IEntityStorageAuthenticationServiceConstructorOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* Implementation of the authentication component using entity storage.
|
|
@@ -62,4 +62,9 @@ export declare class EntityStorageAuthenticationService implements IAuthenticati
|
|
|
62
62
|
* @returns A promise that resolves when the password has been updated and the rate limit cleared.
|
|
63
63
|
*/
|
|
64
64
|
updatePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Get the password policy used for password validation.
|
|
67
|
+
* @returns The password policy options.
|
|
68
|
+
*/
|
|
69
|
+
passwordPolicy(): Promise<IPasswordOptions>;
|
|
65
70
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IPasswordOptions } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
+
import type { IAuthenticationAuditComponent } from "@3sixty/api-auth-models";
|
|
2
3
|
import type { IEntityStorageConnector } from "@3sixty/entity-storage-models";
|
|
3
4
|
import type { AuthenticationUser } from "../entities/authenticationUser.js";
|
|
4
5
|
/**
|
|
@@ -17,8 +18,10 @@ export declare class PasswordHelper {
|
|
|
17
18
|
* @param user The user whose password is being updated.
|
|
18
19
|
* @param newPassword The new password to set.
|
|
19
20
|
* @param currentPassword The current password to verify against, if supplied.
|
|
20
|
-
* @param
|
|
21
|
+
* @param options Optional password length validation options.
|
|
22
|
+
* @param options.minPasswordLength Optional minimum password length for validation.
|
|
23
|
+
* @param options.maxPasswordLength Optional maximum password length for validation.
|
|
21
24
|
* @returns A promise that resolves when the new password has been stored and the audit entry recorded.
|
|
22
25
|
*/
|
|
23
|
-
static updatePassword(userEntityStorage: IEntityStorageConnector<AuthenticationUser>, authenticationAuditService: IAuthenticationAuditComponent | undefined, user: AuthenticationUser, newPassword: string, currentPassword?: string,
|
|
26
|
+
static updatePassword(userEntityStorage: IEntityStorageConnector<AuthenticationUser>, authenticationAuditService: IAuthenticationAuditComponent | undefined, user: AuthenticationUser, newPassword: string, currentPassword?: string, options?: IPasswordOptions): Promise<void>;
|
|
24
27
|
}
|
|
@@ -17,11 +17,10 @@ export declare class TokenHelper {
|
|
|
17
17
|
* @param organizationIdentity The organization for the token.
|
|
18
18
|
* @param tenantId The tenant id for the token.
|
|
19
19
|
* @param ttlMinutes The time to live for the token in minutes.
|
|
20
|
-
* @param scope The scopes for the token.
|
|
21
20
|
* @param passwordVersion The user's current password version counter, embedded in the token so that a password change invalidates existing tokens.
|
|
22
21
|
* @returns The new token and its expiry date.
|
|
23
22
|
*/
|
|
24
|
-
static createToken(vaultConnector: IVaultConnector, nodeId: string, signingKeyName: string, userIdentity: string, organizationIdentity: string | undefined, tenantId: string | undefined, ttlMinutes: number,
|
|
23
|
+
static createToken(vaultConnector: IVaultConnector, nodeId: string, signingKeyName: string, userIdentity: string, organizationIdentity: string | undefined, tenantId: string | undefined, ttlMinutes: number, passwordVersion?: number): Promise<{
|
|
25
24
|
token: string;
|
|
26
25
|
expiry: number;
|
|
27
26
|
}>;
|
|
@@ -31,22 +30,14 @@ export declare class TokenHelper {
|
|
|
31
30
|
* @param nodeId The node identifier, expected to match the JWT issuer claim.
|
|
32
31
|
* @param signingKeyName The signing key name, expected to match the JWT key identifier.
|
|
33
32
|
* @param token The token to verify.
|
|
34
|
-
* @param requiredScopes The required scopes.
|
|
35
33
|
* @param verifyUser A function to verify the user identity and organization. The password version counter embedded in the token (pver claim) is passed so callers can detect if the password has changed since the token was issued.
|
|
36
34
|
* @returns The verified details.
|
|
37
35
|
* @throws UnauthorizedError if the token is missing, invalid or expired.
|
|
38
36
|
*/
|
|
39
|
-
static verify(vaultConnector: IVaultConnector, nodeId: string, signingKeyName: string, token: string | undefined,
|
|
37
|
+
static verify(vaultConnector: IVaultConnector, nodeId: string, signingKeyName: string, token: string | undefined, verifyUser?: (sub: string, org: string, tid: string | undefined, passwordVersion: number | undefined) => Promise<string[]>): Promise<{
|
|
40
38
|
header: IJwtHeader;
|
|
41
39
|
payload: IJwtPayload;
|
|
42
40
|
}>;
|
|
43
|
-
/**
|
|
44
|
-
* Verify that a token carries all of the required scopes.
|
|
45
|
-
* @param scope The comma separated scopes from the token.
|
|
46
|
-
* @param requiredScopes The scopes the caller must hold.
|
|
47
|
-
* @throws UnauthorizedError if any of the required scopes is missing.
|
|
48
|
-
*/
|
|
49
|
-
static verifyScopes(scope: string | undefined, requiredScopes?: string[]): void;
|
|
50
41
|
/**
|
|
51
42
|
* Extract the auth token from the headers, either from the authorization header or the cookie header.
|
|
52
43
|
* @param headers The headers to extract the token from.
|
package/docs/changelog.md
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.20.0-next.1](https://github.com/3sixtyglobal/api-auth/compare/api-auth-entity-storage-service-v0.20.0-next.0...api-auth-entity-storage-service-v0.20.0-next.1) (2026-10-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* authorization ([#3](https://github.com/3sixtyglobal/api-auth/issues/3)) ([5688693](https://github.com/3sixtyglobal/api-auth/commit/568869364065b9d2c82c5c17c81f07cbdc64ec8b))
|
|
9
|
+
* initial commit ([b9112fb](https://github.com/3sixtyglobal/api-auth/commit/b9112fb6994758b43effdde1b9e41435ff50fe50))
|
|
10
|
+
* publish packages under the [@3sixty](https://github.com/3sixty) namespace ([6c22482](https://github.com/3sixtyglobal/api-auth/commit/6c2248295620000807ff91087c3b1dfc9b018b31))
|
|
11
|
+
* updated ts compile ([83c72bd](https://github.com/3sixtyglobal/api-auth/commit/83c72bd5d2e9d81208b7a2755450d96fbbb04004))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Dependencies
|
|
15
|
+
|
|
16
|
+
* The following workspace dependencies were updated
|
|
17
|
+
* dependencies
|
|
18
|
+
* @3sixty/api-auth-entity-storage-models bumped from 0.20.0-next.0 to 0.20.0-next.1
|
|
19
|
+
* @3sixty/api-auth-models bumped from 0.20.0-next.0 to 0.20.0-next.1
|
package/docs/examples.md
CHANGED
|
@@ -15,19 +15,18 @@ await adminService.create({
|
|
|
15
15
|
email: 'owner@example.org',
|
|
16
16
|
password: 'StartPassword123',
|
|
17
17
|
userIdentity: 'did:example:owner',
|
|
18
|
-
organizationIdentity: 'did:example:org'
|
|
19
|
-
scope: ['admin']
|
|
18
|
+
organizationIdentity: 'did:example:org'
|
|
20
19
|
});
|
|
21
20
|
|
|
22
21
|
await adminService.update({
|
|
23
22
|
email: 'owner@example.org',
|
|
24
|
-
|
|
23
|
+
organizationIdentity: 'did:example:org:security'
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
await adminService.updatePassword('owner@example.org', 'StartPassword124', 'StartPassword123');
|
|
28
27
|
|
|
29
28
|
const fromIdentity = await adminService.getByIdentity('did:example:owner');
|
|
30
|
-
console.log(fromIdentity.
|
|
29
|
+
console.log(fromIdentity.organizationIdentity); // did:example:org:security
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
```typescript
|
|
@@ -50,6 +49,9 @@ const authService = new EntityStorageAuthenticationService();
|
|
|
50
49
|
await authService.start('default');
|
|
51
50
|
console.log(authService.className()); // EntityStorageAuthenticationService
|
|
52
51
|
|
|
52
|
+
const policy = await authService.passwordPolicy();
|
|
53
|
+
console.log(policy.minPasswordLength); // 8
|
|
54
|
+
|
|
53
55
|
const loginResult = await authService.login('alice@example.org', 'correct-horse-battery-staple');
|
|
54
56
|
|
|
55
57
|
const refreshResult = await authService.refresh(loginResult.token);
|
|
@@ -58,96 +60,8 @@ await authService.updatePassword('correct-horse-battery-staple', 'correct-horse-
|
|
|
58
60
|
|
|
59
61
|
await authService.logout(refreshResult.token);
|
|
60
62
|
console.log(refreshResult.expiry > 0); // true
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## EntityStorageAuthenticationRateService
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
import { EntityStorageAuthenticationRateService } from '@3sixty/api-auth-entity-storage-service';
|
|
67
|
-
import { BaseError, GeneralError } from '@3sixty/core';
|
|
68
|
-
import { TooManyRequestsError } from '@3sixty/api-models';
|
|
69
|
-
|
|
70
|
-
const rateService = new EntityStorageAuthenticationRateService({
|
|
71
|
-
config: {
|
|
72
|
-
cleanupIntervalMinutes: 5
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
console.log(rateService.className()); // EntityStorageAuthenticationRateService
|
|
77
|
-
|
|
78
|
-
await rateService.registerAction('login', {
|
|
79
|
-
maxAttempts: 3,
|
|
80
|
-
windowMinutes: 15
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await rateService.start('default');
|
|
84
|
-
|
|
85
|
-
await rateService.check('login', 'alice@example.org');
|
|
86
|
-
await rateService.check('login', 'alice@example.org');
|
|
87
|
-
await rateService.check('login', 'alice@example.org');
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
await rateService.check('login', 'alice@example.org');
|
|
91
|
-
} catch (error) {
|
|
92
|
-
if (BaseError.isErrorName(error, TooManyRequestsError.CLASS_NAME)) {
|
|
93
|
-
const tooMany = error as TooManyRequestsError;
|
|
94
|
-
console.log(tooMany.properties?.retryAfterSeconds); // 900
|
|
95
|
-
console.log(tooMany.properties?.nextRequestTime); // 2026-04-13T10:15:00.000Z
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
await rateService.clear('login', 'alice@example.org');
|
|
100
|
-
await rateService.unregisterAction('login');
|
|
101
63
|
|
|
102
|
-
|
|
103
|
-
await rateService.check('login', 'alice@example.org');
|
|
104
|
-
} catch (error) {
|
|
105
|
-
if (BaseError.isErrorName(error, GeneralError.CLASS_NAME)) {
|
|
106
|
-
console.log((error as GeneralError).name); // GeneralError
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
await rateService.stop('default');
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## EntityStorageAuthenticationAuditService
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
import { EntityStorageAuthenticationAuditService } from '@3sixty/api-auth-entity-storage-service';
|
|
117
|
-
|
|
118
|
-
const auditService = new EntityStorageAuthenticationAuditService({
|
|
119
|
-
config: {
|
|
120
|
-
ipHashSalt: 'StrongServerSideSaltForAuditHashing123'
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
console.log(auditService.className()); // EntityStorageAuthenticationAuditService
|
|
125
|
-
|
|
126
|
-
const createdAuditId = await auditService.create({
|
|
127
|
-
event: 'login-failure',
|
|
128
|
-
actorId: 'did:example:user:alice',
|
|
129
|
-
nodeId: 'did:example:node:eu-west-1',
|
|
130
|
-
organizationId: 'did:example:org:core',
|
|
131
|
-
tenantId: 'did:example:tenant:alpha',
|
|
132
|
-
data: {
|
|
133
|
-
reason: 'invalid-password'
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const auditPage = await auditService.query(
|
|
138
|
-
{
|
|
139
|
-
actorId: 'did:example:user:alice',
|
|
140
|
-
event: 'login-failure',
|
|
141
|
-
startDate: '2026-04-01T00:00:00.000Z',
|
|
142
|
-
endDate: '2026-04-30T23:59:59.999Z'
|
|
143
|
-
},
|
|
144
|
-
undefined,
|
|
145
|
-
50
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
console.log(createdAuditId); // 018f2f67bb9d4a0caad8386f56df85ce
|
|
149
|
-
console.log(auditPage.entries.length); // 1
|
|
150
|
-
console.log(auditPage.cursor); // eyJpZCI6IjAxOGYyZjY3YmI5ZDRhMGNhYWQ4Mzg2ZjU2ZGY4NWNlIn0=
|
|
64
|
+
await authService.stop('default');
|
|
151
65
|
```
|
|
152
66
|
|
|
153
67
|
## AuthHeaderProcessor
|
|
@@ -175,4 +89,6 @@ const processorState: { [id: string]: unknown } = {};
|
|
|
175
89
|
await processor.pre(request, response, { skipAuth: false }, contextIds, processorState);
|
|
176
90
|
|
|
177
91
|
await processor.post(request, response, { skipAuth: false }, contextIds, processorState);
|
|
92
|
+
|
|
93
|
+
await processor.stop();
|
|
178
94
|
```
|