@3sixty/api-auth-entity-storage-service 0.0.0-stage → 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/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/entities/authenticationUser.js +61 -0
- package/dist/es/entities/authenticationUser.js.map +1 -0
- package/dist/es/entities/authenticationUserV0.js +69 -0
- package/dist/es/entities/authenticationUserV0.js.map +1 -0
- package/dist/es/index.js +21 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IAuthHeaderProcessorConfig.js +4 -0
- package/dist/es/models/IAuthHeaderProcessorConfig.js.map +1 -0
- package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js +2 -0
- package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/IAuthTokenContext.js +4 -0
- package/dist/es/models/IAuthTokenContext.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js +4 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js.map +1 -0
- package/dist/es/processors/authHeaderProcessor.js +272 -0
- package/dist/es/processors/authHeaderProcessor.js.map +1 -0
- package/dist/es/restEntryPoints.js +20 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js +375 -0
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js.map +1 -0
- package/dist/es/routes/entityStorageAuthenticationRoutes.js +291 -0
- package/dist/es/routes/entityStorageAuthenticationRoutes.js.map +1 -0
- package/dist/es/schema.js +13 -0
- package/dist/es/schema.js.map +1 -0
- package/dist/es/services/entityStorageAuthenticationAdminService.js +324 -0
- package/dist/es/services/entityStorageAuthenticationAdminService.js.map +1 -0
- package/dist/es/services/entityStorageAuthenticationService.js +338 -0
- package/dist/es/services/entityStorageAuthenticationService.js.map +1 -0
- package/dist/es/utils/passwordHelper.js +60 -0
- package/dist/es/utils/passwordHelper.js.map +1 -0
- package/dist/es/utils/tokenHelper.js +121 -0
- package/dist/es/utils/tokenHelper.js.map +1 -0
- package/dist/types/entities/authenticationUser.d.ts +29 -0
- package/dist/types/entities/authenticationUserV0.d.ts +33 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/models/IAuthHeaderProcessorConfig.d.ts +38 -0
- package/dist/types/models/IAuthHeaderProcessorConstructorOptions.d.ts +25 -0
- package/dist/types/models/IAuthTokenContext.d.ts +30 -0
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConfig.d.ts +25 -0
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +25 -0
- package/dist/types/models/IEntityStorageAuthenticationServiceConfig.d.ts +41 -0
- package/dist/types/models/IEntityStorageAuthenticationServiceConstructorOptions.d.ts +35 -0
- package/dist/types/processors/authHeaderProcessor.d.ts +57 -0
- package/dist/types/restEntryPoints.d.ts +5 -0
- package/dist/types/routes/entityStorageAuthenticationAdminRoutes.d.ts +62 -0
- package/dist/types/routes/entityStorageAuthenticationRoutes.d.ts +53 -0
- package/dist/types/schema.d.ts +4 -0
- package/dist/types/services/entityStorageAuthenticationAdminService.d.ts +69 -0
- package/dist/types/services/entityStorageAuthenticationService.d.ts +70 -0
- package/dist/types/utils/passwordHelper.d.ts +27 -0
- package/dist/types/utils/tokenHelper.d.ts +51 -0
- package/docs/changelog.md +19 -0
- package/docs/examples.md +94 -0
- package/docs/open-api/spec.json +1344 -0
- package/docs/reference/classes/AuthHeaderProcessor.md +197 -0
- package/docs/reference/classes/AuthenticationUser.md +61 -0
- package/docs/reference/classes/AuthenticationUserV0.md +69 -0
- package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +237 -0
- package/docs/reference/classes/EntityStorageAuthenticationService.md +239 -0
- package/docs/reference/classes/PasswordHelper.md +74 -0
- package/docs/reference/classes/TokenHelper.md +163 -0
- package/docs/reference/functions/authenticationAdminCreateUser.md +37 -0
- package/docs/reference/functions/authenticationAdminGetUser.md +31 -0
- package/docs/reference/functions/authenticationAdminGetUserByIdentity.md +31 -0
- package/docs/reference/functions/authenticationAdminRemoveUser.md +31 -0
- package/docs/reference/functions/authenticationAdminUpdateUser.md +31 -0
- package/docs/reference/functions/authenticationAdminUpdateUserPassword.md +31 -0
- package/docs/reference/functions/authenticationLogin.md +31 -0
- package/docs/reference/functions/authenticationLogout.md +31 -0
- package/docs/reference/functions/authenticationPasswordPolicy.md +31 -0
- package/docs/reference/functions/authenticationRefreshToken.md +31 -0
- package/docs/reference/functions/authenticationUpdatePassword.md +31 -0
- package/docs/reference/functions/generateRestRoutesAuthentication.md +25 -0
- package/docs/reference/functions/generateRestRoutesAuthenticationAdmin.md +25 -0
- package/docs/reference/functions/initSchema.md +9 -0
- package/docs/reference/index.md +44 -0
- package/docs/reference/interfaces/IAuthHeaderProcessorConfig.md +85 -0
- package/docs/reference/interfaces/IAuthHeaderProcessorConstructorOptions.md +53 -0
- package/docs/reference/interfaces/IAuthTokenContext.md +52 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConfig.md +59 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +53 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConfig.md +101 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md +81 -0
- package/docs/reference/variables/restEntryPoints.md +5 -0
- package/docs/reference/variables/tagsAuthentication.md +5 -0
- package/docs/reference/variables/tagsAuthenticationAdmin.md +5 -0
- package/locales/en.json +37 -0
- package/package.json +63 -5
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { IAuthenticationAdminComponent, IAuthenticationUser } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
+
import type { IEntityStorageAuthenticationAdminServiceConstructorOptions } from "../models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the authentication component using entity storage.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EntityStorageAuthenticationAdminService implements IAuthenticationAdminComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* The default role that grants escalated privilege.
|
|
13
|
+
*/
|
|
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;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of EntityStorageAuthentication.
|
|
21
|
+
* @param options The dependencies for the identity connector.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: IEntityStorageAuthenticationAdminServiceConstructorOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Returns the class name of the component.
|
|
26
|
+
* @returns The class name of the component.
|
|
27
|
+
*/
|
|
28
|
+
className(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Create a login for the user.
|
|
31
|
+
* @param user The user to create.
|
|
32
|
+
* @returns A promise that resolves when the user account has been created and the audit entry recorded.
|
|
33
|
+
*/
|
|
34
|
+
create(user: IAuthenticationUser & {
|
|
35
|
+
password: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Update a login for the user.
|
|
39
|
+
* @param user The user to update.
|
|
40
|
+
* @returns A promise that resolves when the user account has been updated and the audit entry recorded.
|
|
41
|
+
*/
|
|
42
|
+
update(user: Partial<IAuthenticationUser>): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get a user by email.
|
|
45
|
+
* @param email The email address of the user to get.
|
|
46
|
+
* @returns The user details.
|
|
47
|
+
*/
|
|
48
|
+
get(email: string): Promise<IAuthenticationUser>;
|
|
49
|
+
/**
|
|
50
|
+
* Get a user by identity.
|
|
51
|
+
* @param identity The identity of the user to get.
|
|
52
|
+
* @returns The user details.
|
|
53
|
+
*/
|
|
54
|
+
getByIdentity(identity: string): Promise<IAuthenticationUser>;
|
|
55
|
+
/**
|
|
56
|
+
* Remove the current user.
|
|
57
|
+
* @param email The email address of the user to remove.
|
|
58
|
+
* @returns A promise that resolves when the user account has been removed and the audit entry recorded.
|
|
59
|
+
*/
|
|
60
|
+
remove(email: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Update the user's password.
|
|
63
|
+
* @param email The email address of the user to update.
|
|
64
|
+
* @param newPassword The new password for the user.
|
|
65
|
+
* @param currentPassword The current password, optional, if supplied will check against existing.
|
|
66
|
+
* @returns A promise that resolves when the password has been updated.
|
|
67
|
+
*/
|
|
68
|
+
updatePassword(email: string, newPassword: string, currentPassword?: string): Promise<void>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { IAuthenticationComponent, IPasswordOptions } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
+
import type { IEntityStorageAuthenticationServiceConstructorOptions } from "../models/IEntityStorageAuthenticationServiceConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the authentication component using entity storage.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EntityStorageAuthenticationService implements IAuthenticationComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of EntityStorageAuthentication.
|
|
13
|
+
* @param options The dependencies for the identity connector.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: IEntityStorageAuthenticationServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the class name of the component.
|
|
18
|
+
* @returns The class name of the component.
|
|
19
|
+
*/
|
|
20
|
+
className(): string;
|
|
21
|
+
/**
|
|
22
|
+
* The service needs to be started when the application is initialized.
|
|
23
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
24
|
+
* @returns A promise that resolves when rate-limit actions have been registered and the node identity cached.
|
|
25
|
+
*/
|
|
26
|
+
start(nodeLoggingComponentType?: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* The component needs to be stopped when the node is closed.
|
|
29
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
30
|
+
* @returns A promise that resolves when all rate-limit actions have been unregistered.
|
|
31
|
+
*/
|
|
32
|
+
stop(nodeLoggingComponentType?: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Perform a login for the user.
|
|
35
|
+
* @param email The email address for the user.
|
|
36
|
+
* @param password The password for the user.
|
|
37
|
+
* @returns The authentication token for the user, if it uses a mechanism with public access.
|
|
38
|
+
*/
|
|
39
|
+
login(email: string, password: string): Promise<{
|
|
40
|
+
token?: string;
|
|
41
|
+
expiry: number;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Logout the current user.
|
|
45
|
+
* @param token The token to logout, if it uses a mechanism with public access.
|
|
46
|
+
* @returns A promise that resolves when the logout audit entry has been recorded.
|
|
47
|
+
*/
|
|
48
|
+
logout(token?: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Refresh the token.
|
|
51
|
+
* @param token The token to refresh, if it uses a mechanism with public access.
|
|
52
|
+
* @returns The refreshed token, if it uses a mechanism with public access.
|
|
53
|
+
*/
|
|
54
|
+
refresh(token?: string): Promise<{
|
|
55
|
+
token?: string;
|
|
56
|
+
expiry: number;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Update the user's password.
|
|
60
|
+
* @param currentPassword The current password for the user.
|
|
61
|
+
* @param newPassword The new password for the user.
|
|
62
|
+
* @returns A promise that resolves when the password has been updated and the rate limit cleared.
|
|
63
|
+
*/
|
|
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>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IPasswordOptions } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
+
import type { IAuthenticationAuditComponent } from "@3sixty/api-auth-models";
|
|
3
|
+
import type { IEntityStorageConnector } from "@3sixty/entity-storage-models";
|
|
4
|
+
import type { AuthenticationUser } from "../entities/authenticationUser.js";
|
|
5
|
+
/**
|
|
6
|
+
* Helper class for password operations.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PasswordHelper {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static readonly CLASS_NAME: string;
|
|
13
|
+
/**
|
|
14
|
+
* Update the password for a user.
|
|
15
|
+
* Validates password strength, verifies the current password if provided, then hashes and stores the new password and raises an audit event.
|
|
16
|
+
* @param userEntityStorage The entity storage for users.
|
|
17
|
+
* @param authenticationAuditService The optional audit service.
|
|
18
|
+
* @param user The user whose password is being updated.
|
|
19
|
+
* @param newPassword The new password to set.
|
|
20
|
+
* @param currentPassword The current password to verify against, if supplied.
|
|
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.
|
|
24
|
+
* @returns A promise that resolves when the new password has been stored and the audit entry recorded.
|
|
25
|
+
*/
|
|
26
|
+
static updatePassword(userEntityStorage: IEntityStorageConnector<AuthenticationUser>, authenticationAuditService: IAuthenticationAuditComponent | undefined, user: AuthenticationUser, newPassword: string, currentPassword?: string, options?: IPasswordOptions): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type IVaultConnector } from "@3sixty/vault-models";
|
|
2
|
+
import { type IHttpHeaders, type IJwtHeader, type IJwtPayload } from "@3sixty/web";
|
|
3
|
+
/**
|
|
4
|
+
* Helper class for token operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class TokenHelper {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new token.
|
|
13
|
+
* @param vaultConnector The vault connector.
|
|
14
|
+
* @param nodeId The node identifier, embedded as the JWT issuer claim.
|
|
15
|
+
* @param signingKeyName The signing key name, embedded as the JWT key identifier.
|
|
16
|
+
* @param userIdentity The subject for the token.
|
|
17
|
+
* @param organizationIdentity The organization for the token.
|
|
18
|
+
* @param tenantId The tenant id for the token.
|
|
19
|
+
* @param ttlMinutes The time to live for the token in minutes.
|
|
20
|
+
* @param passwordVersion The user's current password version counter, embedded in the token so that a password change invalidates existing tokens.
|
|
21
|
+
* @returns The new token and its expiry date.
|
|
22
|
+
*/
|
|
23
|
+
static createToken(vaultConnector: IVaultConnector, nodeId: string, signingKeyName: string, userIdentity: string, organizationIdentity: string | undefined, tenantId: string | undefined, ttlMinutes: number, passwordVersion?: number): Promise<{
|
|
24
|
+
token: string;
|
|
25
|
+
expiry: number;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Verify the token.
|
|
29
|
+
* @param vaultConnector The vault connector.
|
|
30
|
+
* @param nodeId The node identifier, expected to match the JWT issuer claim.
|
|
31
|
+
* @param signingKeyName The signing key name, expected to match the JWT key identifier.
|
|
32
|
+
* @param token The token to verify.
|
|
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.
|
|
34
|
+
* @returns The verified details.
|
|
35
|
+
* @throws UnauthorizedError if the token is missing, invalid or expired.
|
|
36
|
+
*/
|
|
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<{
|
|
38
|
+
header: IJwtHeader;
|
|
39
|
+
payload: IJwtPayload;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Extract the auth token from the headers, either from the authorization header or the cookie header.
|
|
43
|
+
* @param headers The headers to extract the token from.
|
|
44
|
+
* @param cookieName The name of the cookie to extract the token from.
|
|
45
|
+
* @returns The token if found.
|
|
46
|
+
*/
|
|
47
|
+
static extractTokenFromHeaders(headers?: IHttpHeaders, cookieName?: string): {
|
|
48
|
+
token: string;
|
|
49
|
+
location: "authorization" | "cookie";
|
|
50
|
+
} | undefined;
|
|
51
|
+
}
|
|
@@ -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
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Auth Entity Storage Service Examples
|
|
2
|
+
|
|
3
|
+
These snippets show how to wire authentication services into your component container and apply token processing in request pipelines.
|
|
4
|
+
|
|
5
|
+
## EntityStorageAuthenticationAdminService
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { EntityStorageAuthenticationAdminService } from '@3sixty/api-auth-entity-storage-service';
|
|
9
|
+
|
|
10
|
+
const adminService = new EntityStorageAuthenticationAdminService();
|
|
11
|
+
|
|
12
|
+
console.log(adminService.className()); // EntityStorageAuthenticationAdminService
|
|
13
|
+
|
|
14
|
+
await adminService.create({
|
|
15
|
+
email: 'owner@example.org',
|
|
16
|
+
password: 'StartPassword123',
|
|
17
|
+
userIdentity: 'did:example:owner',
|
|
18
|
+
organizationIdentity: 'did:example:org'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
await adminService.update({
|
|
22
|
+
email: 'owner@example.org',
|
|
23
|
+
organizationIdentity: 'did:example:org:security'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await adminService.updatePassword('owner@example.org', 'StartPassword124', 'StartPassword123');
|
|
27
|
+
|
|
28
|
+
const fromIdentity = await adminService.getByIdentity('did:example:owner');
|
|
29
|
+
console.log(fromIdentity.organizationIdentity); // did:example:org:security
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { EntityStorageAuthenticationAdminService } from '@3sixty/api-auth-entity-storage-service';
|
|
34
|
+
|
|
35
|
+
const adminService = new EntityStorageAuthenticationAdminService();
|
|
36
|
+
const user = await adminService.get('owner@example.org');
|
|
37
|
+
await adminService.remove(user.email);
|
|
38
|
+
|
|
39
|
+
console.log(user.email); // owner@example.org
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## EntityStorageAuthenticationService
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { EntityStorageAuthenticationService } from '@3sixty/api-auth-entity-storage-service';
|
|
46
|
+
|
|
47
|
+
const authService = new EntityStorageAuthenticationService();
|
|
48
|
+
|
|
49
|
+
await authService.start('default');
|
|
50
|
+
console.log(authService.className()); // EntityStorageAuthenticationService
|
|
51
|
+
|
|
52
|
+
const policy = await authService.passwordPolicy();
|
|
53
|
+
console.log(policy.minPasswordLength); // 8
|
|
54
|
+
|
|
55
|
+
const loginResult = await authService.login('alice@example.org', 'correct-horse-battery-staple');
|
|
56
|
+
|
|
57
|
+
const refreshResult = await authService.refresh(loginResult.token);
|
|
58
|
+
|
|
59
|
+
await authService.updatePassword('correct-horse-battery-staple', 'correct-horse-battery-staple-2');
|
|
60
|
+
|
|
61
|
+
await authService.logout(refreshResult.token);
|
|
62
|
+
console.log(refreshResult.expiry > 0); // true
|
|
63
|
+
|
|
64
|
+
await authService.stop('default');
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## AuthHeaderProcessor
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { AuthHeaderProcessor } from '@3sixty/api-auth-entity-storage-service';
|
|
71
|
+
|
|
72
|
+
const processor = new AuthHeaderProcessor();
|
|
73
|
+
|
|
74
|
+
await processor.start('default');
|
|
75
|
+
console.log(processor.className()); // AuthHeaderProcessor
|
|
76
|
+
|
|
77
|
+
const request = {
|
|
78
|
+
method: 'get',
|
|
79
|
+
url: '/info',
|
|
80
|
+
headers: {
|
|
81
|
+
authorization: 'Bearer token-value'
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const response = {};
|
|
86
|
+
const contextIds = {};
|
|
87
|
+
const processorState: { [id: string]: unknown } = {};
|
|
88
|
+
|
|
89
|
+
await processor.pre(request, response, { skipAuth: false }, contextIds, processorState);
|
|
90
|
+
|
|
91
|
+
await processor.post(request, response, { skipAuth: false }, contextIds, processorState);
|
|
92
|
+
|
|
93
|
+
await processor.stop();
|
|
94
|
+
```
|