@open-core/identity 1.2.0 → 1.2.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/dist/contracts.d.ts +93 -0
- package/dist/contracts.js +21 -0
- package/dist/index.d.ts +86 -67
- package/dist/index.js +107 -56
- package/dist/providers/auth/api-auth.provider.d.ts +52 -0
- package/dist/providers/auth/api-auth.provider.js +82 -0
- package/dist/providers/auth/credentials-auth.provider.d.ts +63 -0
- package/dist/providers/auth/credentials-auth.provider.js +149 -0
- package/dist/providers/auth/local-auth.provider.d.ts +82 -0
- package/dist/providers/auth/local-auth.provider.js +151 -0
- package/dist/providers/identity-auth.provider.d.ts +0 -0
- package/dist/providers/identity-auth.provider.js +1 -0
- package/dist/providers/principal/api-principal.provider.d.ts +50 -0
- package/dist/providers/principal/api-principal.provider.js +84 -0
- package/dist/providers/principal/local-principal.provider.d.ts +77 -0
- package/dist/providers/principal/local-principal.provider.js +164 -0
- package/dist/services/account.service.d.ts +52 -57
- package/dist/services/account.service.js +77 -160
- package/dist/services/role.service.d.ts +33 -54
- package/dist/services/role.service.js +48 -103
- package/dist/tokens.d.ts +7 -0
- package/dist/tokens.js +7 -0
- package/dist/types.d.ts +170 -0
- package/dist/types.js +1 -0
- package/package.json +1 -1
|
@@ -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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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 {
|
|
54
|
-
export
|
|
55
|
-
export
|
|
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 "./
|
|
88
|
+
export * from "./tokens";
|
|
89
|
+
export default Identity;
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Identity.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
//
|
|
40
|
-
export {
|
|
41
|
-
export
|
|
42
|
-
export
|
|
43
|
-
|
|
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 "./
|
|
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
|
+
}
|