@open-core/identity 1.2.0 → 1.2.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.
package/README.md CHANGED
@@ -23,9 +23,7 @@ The recommended way to use the identity system is through **Constructor Injectio
23
23
  ```ts
24
24
  import { Server } from "@open-core/framework";
25
25
  import { AccountService } from "@open-core/identity";
26
- import { injectable } from "tsyringe";
27
26
 
28
- @injectable()
29
27
  @Server.Controller()
30
28
  export class MyController {
31
29
  // AccountService is automatically injected
@@ -0,0 +1,93 @@
1
+ import type { IdentityAccount, IdentityRole } from "./types";
2
+ /**
3
+ * Persistence contract for identity accounts.
4
+ *
5
+ * Implement this interface to provide a storage backend (SQL, NoSQL, or API)
6
+ * for account-related operations. The identity system depends on this contract
7
+ * to lookup and manage persistent player state.
8
+ *
9
+ * @public
10
+ */
11
+ export declare abstract class IdentityStore {
12
+ /**
13
+ * Retrieves an account by its primary connection identifier.
14
+ *
15
+ * @param identifier - The unique identifier (e.g., 'license:123...').
16
+ * @returns A promise resolving to the account or null if not found.
17
+ */
18
+ abstract findByIdentifier(identifier: string): Promise<IdentityAccount | null>;
19
+ /**
20
+ * Retrieves an account by its linked stable ID.
21
+ *
22
+ * @param linkedId - The stable ID (e.g., a UUID).
23
+ * @returns A promise resolving to the account or null if not found.
24
+ */
25
+ abstract findByLinkedId(linkedId: string): Promise<IdentityAccount | null>;
26
+ /**
27
+ * Retrieves an account by its unique username.
28
+ *
29
+ * @param username - The technical username.
30
+ * @returns A promise resolving to the account or null if not found.
31
+ */
32
+ abstract findByUsername(username: string): Promise<IdentityAccount | null>;
33
+ /**
34
+ * Persists a new identity account.
35
+ *
36
+ * @param data - Initial account properties.
37
+ * @returns A promise resolving to the fully created account object.
38
+ */
39
+ abstract create(data: Partial<IdentityAccount> & {
40
+ passwordHash?: string;
41
+ }): Promise<IdentityAccount>;
42
+ /**
43
+ * Updates an existing account's metadata or status.
44
+ *
45
+ * @param id - The internal account ID.
46
+ * @param data - Partial object containing fields to update.
47
+ */
48
+ abstract update(id: string, data: Partial<IdentityAccount>): Promise<void>;
49
+ /**
50
+ * Prohibits or allows an account from connecting.
51
+ *
52
+ * @param id - The internal account ID.
53
+ * @param banned - Connection status (true to block).
54
+ * @param reason - Optional explanation for the ban.
55
+ * @param expiresAt - Optional expiration timestamp.
56
+ */
57
+ abstract setBan(id: string, banned: boolean, reason?: string, expiresAt?: Date | null): Promise<void>;
58
+ }
59
+ /**
60
+ * Persistence contract for security roles.
61
+ *
62
+ * Implement this interface if your system requires dynamic role management
63
+ * from a database. If using code-first roles, this contract is optional.
64
+ *
65
+ * @public
66
+ */
67
+ export declare abstract class RoleStore {
68
+ /**
69
+ * Retrieves a role definition by its technical name.
70
+ *
71
+ * @param name - Technical name (e.g., 'admin').
72
+ * @returns A promise resolving to the role or null if not found.
73
+ */
74
+ abstract findByName(name: string): Promise<IdentityRole | null>;
75
+ /**
76
+ * Resolves the default role for newly connected accounts.
77
+ *
78
+ * @returns A promise resolving to the default role definition.
79
+ */
80
+ abstract getDefaultRole(): Promise<IdentityRole>;
81
+ /**
82
+ * Creates or updates a role definition.
83
+ *
84
+ * @param role - The complete role object.
85
+ */
86
+ abstract save(role: IdentityRole): Promise<void>;
87
+ /**
88
+ * Removes a role from the system.
89
+ *
90
+ * @param name - Technical name of the role to delete.
91
+ */
92
+ abstract delete(name: string): Promise<void>;
93
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Persistence contract for identity accounts.
3
+ *
4
+ * Implement this interface to provide a storage backend (SQL, NoSQL, or API)
5
+ * for account-related operations. The identity system depends on this contract
6
+ * to lookup and manage persistent player state.
7
+ *
8
+ * @public
9
+ */
10
+ export class IdentityStore {
11
+ }
12
+ /**
13
+ * Persistence contract for security roles.
14
+ *
15
+ * Implement this interface if your system requires dynamic role management
16
+ * from a database. If using code-first roles, this contract is optional.
17
+ *
18
+ * @public
19
+ */
20
+ export class RoleStore {
21
+ }
package/dist/index.d.ts CHANGED
@@ -1,70 +1,89 @@
1
- import * as Setup from "./setup";
2
- import type * as Entities from "./entities/account.entity";
3
- import type * as RoleEntities from "./entities/role.entity";
4
- import * as AccountRepo from "./repositories/account.repository";
5
- import * as RoleRepo from "./repositories/role.repository";
6
- import * as AcctService from "./services/account.service";
7
- import * as RService from "./services/role.service";
8
- import * as CacheService from "./services/cache/memory-cache.service";
9
- import * as LocalAuth from "./services/auth/local-auth.provider";
10
- import * as CredentialsAuth from "./services/auth/credentials-auth.provider";
11
- import * as ApiAuth from "./services/auth/api-auth.provider";
12
- import * as LocalPrincipal from "./services/principal/local-principal.provider";
13
- import * as ApiPrincipal from "./services/principal/api-principal.provider";
14
- import * as AuthProvider from "./services/identity-auth.provider";
15
- import * as PrincipalProvider from "./services/identity-principal.provider";
16
- import type * as Types from "./types";
17
- import type * as AuthTypes from "./types/auth.types";
18
- import type * as Events from "./events/identity.events";
1
+ import { LocalAuthProvider as LocalAuthImpl } from "./providers/auth/local-auth.provider";
2
+ import { CredentialsAuthProvider as CredentialsAuthImpl } from "./providers/auth/credentials-auth.provider";
3
+ import { ApiAuthProvider as ApiAuthImpl } from "./providers/auth/api-auth.provider";
4
+ import { IdentityPrincipalProvider as PrincipalProviderImpl } from "./providers/principal/local-principal.provider";
5
+ import { ApiPrincipalProvider as ApiPrincipalImpl } from "./providers/principal/api-principal.provider";
6
+ import { AccountService as AccountServiceImpl } from "./services/account.service";
7
+ import { RoleService as RoleServiceImpl } from "./services/role.service";
8
+ import { IdentityStore as IdentityStoreContract, RoleStore as RoleStoreContract } from "./contracts";
9
+ import type { IdentityOptions as OptionsType, IdentityRole as RoleType, IdentityAccount as AccountType, AuthMode as AuthModeType, PrincipalMode as PrincipalModeType } from "./types";
10
+ /**
11
+ * OpenCore Identity Namespace
12
+ *
13
+ * Provides a centralized identity, authentication, and authorization system
14
+ * designed to integrate seamlessly with the OpenCore Framework SPI.
15
+ *
16
+ * @public
17
+ */
19
18
  export declare namespace Identity {
20
- const setup: typeof Setup.setupIdentity;
21
- type SetupOptions = Setup.IdentitySetupOptions;
22
- type Account = Entities.Account;
23
- type Role = RoleEntities.Role;
24
- export import AccountRepository = AccountRepo.AccountRepository;
25
- export import RoleRepository = RoleRepo.RoleRepository;
26
- export import AccountService = AcctService.AccountService;
27
- export import RoleService = RService.RoleService;
28
- export import MemoryCacheService = CacheService.MemoryCacheService;
29
- export import LocalAuthProvider = LocalAuth.LocalAuthProvider;
30
- export import CredentialsAuthProvider = CredentialsAuth.CredentialsAuthProvider;
31
- export import ApiAuthProvider = ApiAuth.ApiAuthProvider;
32
- export import LocalPrincipalProvider = LocalPrincipal.LocalPrincipalProvider;
33
- export import ApiPrincipalProvider = ApiPrincipal.ApiPrincipalProvider;
34
- export import IdentityAuthProvider = AuthProvider.IdentityAuthProvider;
35
- export import IdentityPrincipalProvider = PrincipalProvider.IdentityPrincipalProvider;
36
- type IdentifierType = Types.IdentifierType;
37
- type AccountIdentifiers = Types.AccountIdentifiers;
38
- type CreateAccountInput = Types.CreateAccountInput;
39
- type BanOptions = Types.BanOptions;
40
- type AuthSession = Types.AuthSession;
41
- type CreateRoleInput = Types.CreateRoleInput;
42
- type UpdateRoleInput = Types.UpdateRoleInput;
43
- type ApiAuthConfig = AuthTypes.ApiAuthConfig;
44
- type ApiAuthResponse = AuthTypes.ApiAuthResponse;
45
- type ApiPrincipalResponse = AuthTypes.ApiPrincipalResponse;
46
- type CacheOptions = AuthTypes.CacheOptions;
47
- type AccountCreatedEvent = Events.AccountCreatedEvent;
48
- type AccountBannedEvent = Events.AccountBannedEvent;
49
- type AccountUnbannedEvent = Events.AccountUnbannedEvent;
50
- type AccountLoggedInEvent = Events.AccountLoggedInEvent;
51
- type IdentityEventMap = Events.IdentityEventMap;
19
+ /**
20
+ * Registers a custom identity store implementation.
21
+ * Must be called before `Identity.install()`.
22
+ *
23
+ * @param store - The class implementation of the IdentityStore contract.
24
+ */
25
+ function setIdentityStore(store: {
26
+ new (...args: any[]): IdentityStoreContract;
27
+ }): void;
28
+ /**
29
+ * Registers a custom role store implementation.
30
+ * Required for 'db' principal mode. Must be called before `Identity.install()`.
31
+ *
32
+ * @param store - The class implementation of the RoleStore contract.
33
+ */
34
+ function setRoleStore(store: {
35
+ new (...args: any[]): RoleStoreContract;
36
+ }): void;
37
+ /**
38
+ * Installs the Identity plugin into the OpenCore Framework.
39
+ *
40
+ * This function registers the necessary Authentication and Principal providers
41
+ * into the framework's SPI via `Server.setAuthProvider` and `Server.setPrincipalProvider`.
42
+ *
43
+ * @param options - Configuration options for the identity system.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * Identity.install({
48
+ * auth: { mode: 'local', autoCreate: true },
49
+ * principal: {
50
+ * mode: 'roles',
51
+ * roles: {
52
+ * admin: { name: 'admin', rank: 100, permissions: ['*'] },
53
+ * user: { name: 'user', rank: 0, permissions: ['chat.use'] }
54
+ * }
55
+ * }
56
+ * });
57
+ * ```
58
+ */
59
+ function install(options: OptionsType): void;
60
+ type IdentityOptions = OptionsType;
61
+ type IdentityRole = RoleType;
62
+ type IdentityAccount = AccountType;
63
+ type AuthMode = AuthModeType;
64
+ type PrincipalMode = PrincipalModeType;
65
+ /** Identity account persistence contract */
66
+ type IdentityStore = IdentityStoreContract;
67
+ /** Role definition persistence contract */
68
+ type RoleStore = RoleStoreContract;
69
+ /** Service for managing identity accounts */
70
+ type AccountService = AccountServiceImpl;
71
+ /** Service for managing security roles */
72
+ type RoleService = RoleServiceImpl;
73
+ /** Local (identifier-based) authentication provider */
74
+ type LocalAuthProvider = LocalAuthImpl;
75
+ /** Credentials (username/password) authentication provider */
76
+ type CredentialsAuthProvider = CredentialsAuthImpl;
77
+ /** API-based authentication provider */
78
+ type ApiAuthProvider = ApiAuthImpl;
79
+ /** Framework-integrated authorization provider */
80
+ type IdentityPrincipalProvider = PrincipalProviderImpl;
81
+ /** API-based authorization provider */
82
+ type ApiPrincipalProvider = ApiPrincipalImpl;
52
83
  }
53
- export { setupIdentity, type IdentitySetupOptions } from "./setup";
54
- export * from "./entities/account.entity";
55
- export * from "./entities/role.entity";
56
- export * from "./repositories/account.repository";
57
- export * from "./repositories/role.repository";
58
- export * from "./services/account.service";
59
- export * from "./services/role.service";
60
- export * from "./services/cache/memory-cache.service";
61
- export * from "./services/auth/local-auth.provider";
62
- export * from "./services/auth/credentials-auth.provider";
63
- export * from "./services/auth/api-auth.provider";
64
- export * from "./services/principal/local-principal.provider";
65
- export * from "./services/principal/api-principal.provider";
66
- export * from "./services/identity-auth.provider";
67
- export * from "./services/identity-principal.provider";
68
- export * from "./events/identity.events";
84
+ export { AccountServiceImpl as AccountService };
85
+ export { RoleServiceImpl as RoleService };
86
+ export { IdentityStoreContract as IdentityStore, RoleStoreContract as RoleStore };
69
87
  export * from "./types";
70
- export * from "./types/auth.types";
88
+ export * from "./tokens";
89
+ export default Identity;
package/dist/index.js CHANGED
@@ -1,60 +1,111 @@
1
- // Imports for namespace
2
- import * as Setup from "./setup";
3
- import * as AccountRepo from "./repositories/account.repository";
4
- import * as RoleRepo from "./repositories/role.repository";
5
- import * as AcctService from "./services/account.service";
6
- import * as RService from "./services/role.service";
7
- import * as CacheService from "./services/cache/memory-cache.service";
8
- import * as LocalAuth from "./services/auth/local-auth.provider";
9
- import * as CredentialsAuth from "./services/auth/credentials-auth.provider";
10
- import * as ApiAuth from "./services/auth/api-auth.provider";
11
- import * as LocalPrincipal from "./services/principal/local-principal.provider";
12
- import * as ApiPrincipal from "./services/principal/api-principal.provider";
13
- import * as AuthProvider from "./services/identity-auth.provider";
14
- import * as PrincipalProvider from "./services/identity-principal.provider";
15
- // Namespace for organized exports
16
- // eslint-disable-next-line @typescript-eslint/no-namespace
1
+ import { Server } from "@open-core/framework";
2
+ import { IDENTITY_OPTIONS } from "./tokens";
3
+ import { LocalAuthProvider as LocalAuthImpl } from "./providers/auth/local-auth.provider";
4
+ import { CredentialsAuthProvider as CredentialsAuthImpl } from "./providers/auth/credentials-auth.provider";
5
+ import { ApiAuthProvider as ApiAuthImpl } from "./providers/auth/api-auth.provider";
6
+ import { IdentityPrincipalProvider as PrincipalProviderImpl } from "./providers/principal/local-principal.provider";
7
+ import { ApiPrincipalProvider as ApiPrincipalImpl } from "./providers/principal/api-principal.provider";
8
+ import { AccountService as AccountServiceImpl } from "./services/account.service";
9
+ import { RoleService as RoleServiceImpl } from "./services/role.service";
10
+ import { IdentityStore as IdentityStoreContract, RoleStore as RoleStoreContract } from "./contracts";
11
+ /**
12
+ * OpenCore Identity Namespace
13
+ *
14
+ * Provides a centralized identity, authentication, and authorization system
15
+ * designed to integrate seamlessly with the OpenCore Framework SPI.
16
+ *
17
+ * @public
18
+ */
17
19
  export var Identity;
18
20
  (function (Identity) {
19
- // Setup
20
- Identity.setup = Setup.setupIdentity;
21
- // Repositories
22
- Identity.AccountRepository = AccountRepo.AccountRepository;
23
- Identity.RoleRepository = RoleRepo.RoleRepository;
24
- // Services
25
- Identity.AccountService = AcctService.AccountService;
26
- Identity.RoleService = RService.RoleService;
27
- Identity.MemoryCacheService = CacheService.MemoryCacheService;
28
- // Auth Providers
29
- Identity.LocalAuthProvider = LocalAuth.LocalAuthProvider;
30
- Identity.CredentialsAuthProvider = CredentialsAuth.CredentialsAuthProvider;
31
- Identity.ApiAuthProvider = ApiAuth.ApiAuthProvider;
32
- // Principal Providers
33
- Identity.LocalPrincipalProvider = LocalPrincipal.LocalPrincipalProvider;
34
- Identity.ApiPrincipalProvider = ApiPrincipal.ApiPrincipalProvider;
35
- // Legacy providers (for backward compatibility)
36
- Identity.IdentityAuthProvider = AuthProvider.IdentityAuthProvider;
37
- Identity.IdentityPrincipalProvider = PrincipalProvider.IdentityPrincipalProvider;
21
+ /**
22
+ * Registers a custom identity store implementation.
23
+ * Must be called before `Identity.install()`.
24
+ *
25
+ * @param store - The class implementation of the IdentityStore contract.
26
+ */
27
+ function setIdentityStore(store) {
28
+ const container = globalThis.oc_container;
29
+ if (!container)
30
+ throwContainerError();
31
+ container.registerSingleton(IdentityStoreContract, store);
32
+ }
33
+ Identity.setIdentityStore = setIdentityStore;
34
+ /**
35
+ * Registers a custom role store implementation.
36
+ * Required for 'db' principal mode. Must be called before `Identity.install()`.
37
+ *
38
+ * @param store - The class implementation of the RoleStore contract.
39
+ */
40
+ function setRoleStore(store) {
41
+ const container = globalThis.oc_container;
42
+ if (!container)
43
+ throwContainerError();
44
+ container.registerSingleton(RoleStoreContract, store);
45
+ }
46
+ Identity.setRoleStore = setRoleStore;
47
+ function throwContainerError() {
48
+ throw new Error("[OpenCore-Identity] Global container (globalThis.oc_container) not found. " +
49
+ "Ensure the framework is initialized before installing plugins.");
50
+ }
51
+ /**
52
+ * Installs the Identity plugin into the OpenCore Framework.
53
+ *
54
+ * This function registers the necessary Authentication and Principal providers
55
+ * into the framework's SPI via `Server.setAuthProvider` and `Server.setPrincipalProvider`.
56
+ *
57
+ * @param options - Configuration options for the identity system.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * Identity.install({
62
+ * auth: { mode: 'local', autoCreate: true },
63
+ * principal: {
64
+ * mode: 'roles',
65
+ * roles: {
66
+ * admin: { name: 'admin', rank: 100, permissions: ['*'] },
67
+ * user: { name: 'user', rank: 0, permissions: ['chat.use'] }
68
+ * }
69
+ * }
70
+ * });
71
+ * ```
72
+ */
73
+ function install(options) {
74
+ const container = globalThis.oc_container;
75
+ if (!container) {
76
+ throwContainerError();
77
+ }
78
+ // Register options (interface requires manual token)
79
+ container.registerInstance(IDENTITY_OPTIONS, options);
80
+ // Register Internal Services (concrete classes as tokens)
81
+ container.registerSingleton(AccountServiceImpl);
82
+ container.registerSingleton(RoleServiceImpl);
83
+ // Configure Auth SPI based on mode
84
+ if (options.auth.mode === "api") {
85
+ Server.setAuthProvider(ApiAuthImpl);
86
+ }
87
+ else if (options.auth.mode === "credentials") {
88
+ Server.setAuthProvider(CredentialsAuthImpl);
89
+ }
90
+ else {
91
+ Server.setAuthProvider(LocalAuthImpl);
92
+ }
93
+ // Configure Principal SPI based on mode
94
+ if (options.principal.mode === "api") {
95
+ Server.setPrincipalProvider(ApiPrincipalImpl);
96
+ }
97
+ else {
98
+ Server.setPrincipalProvider(PrincipalProviderImpl);
99
+ }
100
+ }
101
+ Identity.install = install;
38
102
  })(Identity || (Identity = {}));
39
- // Top-level exports for backward compatibility
40
- export { setupIdentity } from "./setup";
41
- export * from "./entities/account.entity";
42
- export * from "./entities/role.entity";
43
- export * from "./repositories/account.repository";
44
- export * from "./repositories/role.repository";
45
- export * from "./services/account.service";
46
- export * from "./services/role.service";
47
- export * from "./services/cache/memory-cache.service";
48
- // Auth providers
49
- export * from "./services/auth/local-auth.provider";
50
- export * from "./services/auth/credentials-auth.provider";
51
- export * from "./services/auth/api-auth.provider";
52
- // Principal providers
53
- export * from "./services/principal/local-principal.provider";
54
- export * from "./services/principal/api-principal.provider";
55
- // Legacy providers
56
- export * from "./services/identity-auth.provider";
57
- export * from "./services/identity-principal.provider";
58
- export * from "./events/identity.events";
103
+ // Re-export high-level API
104
+ export { AccountServiceImpl as AccountService };
105
+ export { RoleServiceImpl as RoleService };
106
+ export { IdentityStoreContract as IdentityStore, RoleStoreContract as RoleStore };
107
+ // Export types and tokens for consumers
59
108
  export * from "./types";
60
- export * from "./types/auth.types";
109
+ export * from "./tokens";
110
+ // Default export
111
+ export default Identity;
@@ -0,0 +1,52 @@
1
+ import { Server } from "@open-core/framework";
2
+ import type { IdentityOptions } from "../../types";
3
+ /**
4
+ * Authentication provider that delegates logic to an external HTTP API.
5
+ *
6
+ * This provider implements the framework's {@link Server.AuthProviderContract} by
7
+ * performing network requests to a remote authentication service. It is suitable
8
+ * for environments with a centralized user database or SSO.
9
+ *
10
+ * @injectable
11
+ * @public
12
+ */
13
+ export declare class ApiAuthProvider extends Server.AuthProviderContract {
14
+ private readonly options;
15
+ private readonly http;
16
+ /**
17
+ * Initializes a new instance of the ApiAuthProvider.
18
+ *
19
+ * @param options - Identity system configuration options.
20
+ * @param http - Framework HTTP service for remote communication.
21
+ */
22
+ constructor(options: IdentityOptions, http: Server.HttpService);
23
+ /**
24
+ * Authenticates a player by sending credentials to the external API.
25
+ *
26
+ * @param player - The framework player entity.
27
+ * @param credentials - Authentication data (e.g., tokens, external IDs).
28
+ * @returns A promise resolving to the remote authentication result.
29
+ */
30
+ authenticate(player: Server.Player, credentials: Record<string, unknown>): Promise<Server.AuthResult>;
31
+ /**
32
+ * Registers a player identity via the external API.
33
+ *
34
+ * @param player - The player to register.
35
+ * @param credentials - Registration data.
36
+ * @returns A promise resolving to the remote registration result.
37
+ */
38
+ register(player: Server.Player, credentials: Record<string, unknown>): Promise<Server.AuthResult>;
39
+ /**
40
+ * Validates the player's remote session.
41
+ *
42
+ * @param player - The framework player entity.
43
+ * @returns A promise resolving to the remote session validation result.
44
+ */
45
+ validateSession(player: Server.Player): Promise<Server.AuthResult>;
46
+ /**
47
+ * Notifies the external API that the player has logged out.
48
+ *
49
+ * @param player - The framework player entity.
50
+ */
51
+ logout(player: Server.Player): Promise<void>;
52
+ }
@@ -0,0 +1,82 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { injectable, inject } from "tsyringe";
14
+ import { Server } from "@open-core/framework";
15
+ import { IDENTITY_OPTIONS } from "../../tokens";
16
+ /**
17
+ * Authentication provider that delegates logic to an external HTTP API.
18
+ *
19
+ * This provider implements the framework's {@link Server.AuthProviderContract} by
20
+ * performing network requests to a remote authentication service. It is suitable
21
+ * for environments with a centralized user database or SSO.
22
+ *
23
+ * @injectable
24
+ * @public
25
+ */
26
+ let ApiAuthProvider = class ApiAuthProvider extends Server.AuthProviderContract {
27
+ /**
28
+ * Initializes a new instance of the ApiAuthProvider.
29
+ *
30
+ * @param options - Identity system configuration options.
31
+ * @param http - Framework HTTP service for remote communication.
32
+ */
33
+ constructor(options, http) {
34
+ super();
35
+ this.options = options;
36
+ this.http = http;
37
+ }
38
+ /**
39
+ * Authenticates a player by sending credentials to the external API.
40
+ *
41
+ * @param player - The framework player entity.
42
+ * @param credentials - Authentication data (e.g., tokens, external IDs).
43
+ * @returns A promise resolving to the remote authentication result.
44
+ */
45
+ async authenticate(player, credentials) {
46
+ // Placeholder: Implementation would use this.http.post(...)
47
+ return { success: false, error: "API Auth implementation pending" };
48
+ }
49
+ /**
50
+ * Registers a player identity via the external API.
51
+ *
52
+ * @param player - The player to register.
53
+ * @param credentials - Registration data.
54
+ * @returns A promise resolving to the remote registration result.
55
+ */
56
+ async register(player, credentials) {
57
+ return { success: false, error: "API Registration implementation pending" };
58
+ }
59
+ /**
60
+ * Validates the player's remote session.
61
+ *
62
+ * @param player - The framework player entity.
63
+ * @returns A promise resolving to the remote session validation result.
64
+ */
65
+ async validateSession(player) {
66
+ return { success: false, error: "API session validation pending" };
67
+ }
68
+ /**
69
+ * Notifies the external API that the player has logged out.
70
+ *
71
+ * @param player - The framework player entity.
72
+ */
73
+ async logout(player) {
74
+ // API logout logic
75
+ }
76
+ };
77
+ ApiAuthProvider = __decorate([
78
+ injectable(),
79
+ __param(0, inject(IDENTITY_OPTIONS)),
80
+ __metadata("design:paramtypes", [Object, Server.HttpService])
81
+ ], ApiAuthProvider);
82
+ export { ApiAuthProvider };
@@ -0,0 +1,63 @@
1
+ import { Server } from "@open-core/framework";
2
+ import { IdentityStore } from "../../contracts";
3
+ import type { IdentityOptions } from "../../types";
4
+ /**
5
+ * Authentication provider for username and password credentials.
6
+ *
7
+ * This provider implements the framework's {@link Server.AuthProviderContract} using
8
+ * bcrypt for password hashing and validation. It requires an implementation
9
+ * of {@link IdentityStore} that supports username-based lookups.
10
+ *
11
+ * @injectable
12
+ * @public
13
+ */
14
+ export declare class CredentialsAuthProvider extends Server.AuthProviderContract {
15
+ private readonly options;
16
+ private readonly store;
17
+ /** Cost factor for bcrypt hashing */
18
+ private readonly saltRounds;
19
+ /**
20
+ * Initializes a new instance of the CredentialsAuthProvider.
21
+ *
22
+ * @param options - Identity system configuration options.
23
+ * @param store - Persistence layer for account and credential data.
24
+ */
25
+ constructor(options: IdentityOptions, store: IdentityStore);
26
+ /**
27
+ * Authenticates a player using a username and password.
28
+ *
29
+ * @param player - The framework player entity.
30
+ * @param credentials - Object containing `username` and `password` strings.
31
+ * @returns A promise resolving to the authentication result.
32
+ */
33
+ authenticate(player: Server.Player, credentials: Record<string, unknown>): Promise<Server.AuthResult>;
34
+ /**
35
+ * Registers a new account with a username and password.
36
+ *
37
+ * @param player - The framework player entity.
38
+ * @param credentials - Object containing `username` and `password` strings.
39
+ * @returns A promise resolving to the registration result.
40
+ */
41
+ register(player: Server.Player, credentials: Record<string, unknown>): Promise<Server.AuthResult>;
42
+ /**
43
+ * Validates if the player's current linked account session is still active.
44
+ *
45
+ * @param player - The framework player entity.
46
+ * @returns A promise resolving to the validation result.
47
+ */
48
+ validateSession(player: Server.Player): Promise<Server.AuthResult>;
49
+ /**
50
+ * Performs logout logic for the player.
51
+ *
52
+ * @param player - The framework player entity.
53
+ */
54
+ logout(player: Server.Player): Promise<void>;
55
+ /**
56
+ * Internal helper to determine if an account is currently prohibited.
57
+ *
58
+ * @param account - The account to check.
59
+ * @returns True if the account is banned and the ban hasn't expired.
60
+ * @internal
61
+ */
62
+ private isBanned;
63
+ }