@fonoster/identity 0.18.2 → 0.19.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 +11 -138
- package/dist/allowList.d.ts +25 -0
- package/dist/allowList.js +42 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/server/config.d.ts +276 -0
- package/dist/server/config.js +154 -0
- package/dist/server/httpBridge.d.ts +10 -0
- package/dist/server/httpBridge.js +59 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +104 -0
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[](https://discord.gg/4QWgSz4hTC)  
|
|
2
2
|
|
|
3
|
-
This document
|
|
3
|
+
This document is a high-level overview of the Identity module, helpful for maintainers, contributors, and developers who want to understand its architecture and design or contribute to it.
|
|
4
4
|
|
|
5
5
|
This module is part of the [Fonoster](https://fonoster.com) project. It does not do much by itself. It is intended to be combined with other modules to create a complete solution. For more information about the project, please visit [https://github.com/fonoster/fonoster](https://github.com/fonoster/fonoster).
|
|
6
6
|
|
|
@@ -16,145 +16,18 @@ The Fonoster Identity Module provides the cornerstone for secure user management
|
|
|
16
16
|
|
|
17
17
|
## Key Features
|
|
18
18
|
|
|
19
|
-
This module offers comprehensive identity management functionality, including creating, reading, updating, and deleting user and workspace entities. Users may represent individual accounts or service accounts. Workspaces
|
|
19
|
+
This module offers comprehensive identity management functionality, including creating, reading, updating, and deleting user and workspace entities. Users may represent individual accounts or service accounts. Workspaces organize users and streamline permission administration; a user can belong to multiple workspaces.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
- **Authentication** via JSON Web Tokens (JWTs) — username/password, Multi-Factor Authentication (MFA), OAuth2, and token exchange.
|
|
22
|
+
- **Authorization** via Role-Based Access Control (RBAC) with predefined and custom roles.
|
|
23
|
+
- **Resource ownership** keyed by `accessKeyId` (`US…` for users, `WO…` for workspaces).
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
## Specification
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
The normative specification for this module — entities and resource ownership, the RBAC model, the
|
|
28
|
+
id/access/refresh token model, token exchanges, RS256 verification via `GetPublicKey`, and security
|
|
29
|
+
practices — lives in OpenSpec and is the source of truth:
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
➡️ [`openspec/specs/identity/spec.md`](../../openspec/specs/identity/spec.md)
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
In the case of Fonoster, we might have the Owner, Admin, and Member as Roles associated with a Workspace. In such cases, the Owner will be able to perform all actions, the Admin will be allowed to perform all actions except removing the Workspace, and members will have the ability to make changes to specific resources but not be able to see billing information.
|
|
32
|
-
|
|
33
|
-
## Resource Ownership
|
|
34
|
-
|
|
35
|
-
All resources created within Fonoster have an owner. The owner may be a user or a workspace. For example, a user may own a workspace/workspace, and a workspace can own applications, phone numbers, domains, etc.
|
|
36
|
-
|
|
37
|
-
Creating a resource within a workspace automatically marks it with the workspace's identifier (the accessKeyId).
|
|
38
|
-
|
|
39
|
-
> The `accessKeyId` for a user always starts with the prefix `US`, while the `accessKeyId` for a workspace starts with the prefix `WO`, which helps identify the resource owner type.
|
|
40
|
-
|
|
41
|
-
## Role-Based Access Control
|
|
42
|
-
|
|
43
|
-
Fonoster Identity relies on Role-Based Access Control (RBAC) to offer granular control over parts of the system. The following type can describe the policy for RBAC within Fonoster Identity.
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
[ { "name": "string", "description": "string", "access": string [] } ]
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
The access array consists of the path for an individual gRPC function.
|
|
50
|
-
|
|
51
|
-
Policy Example:
|
|
52
|
-
|
|
53
|
-
```json
|
|
54
|
-
{
|
|
55
|
-
"name": "user",
|
|
56
|
-
"description": "Access to User and Workspace endpoints",
|
|
57
|
-
"access": [
|
|
58
|
-
"/fonoster.identity.v1beta2.Identity/GetUser",
|
|
59
|
-
"/fonoster.identity.v1beta2.Identity/UpdateUser",
|
|
60
|
-
"/fonoster.identity.v1beta2.Identity/DeleteUser",
|
|
61
|
-
"/fonoster.identity.v1beta2.Identity/CreateWorkspace",
|
|
62
|
-
"/fonoster.identity.v1beta2.Identity/GetWorkspace",
|
|
63
|
-
"/fonoster.identity.v1beta2.Identity/UpdateWorkspace",
|
|
64
|
-
"/fonoster.identity.v1beta2.Identity/ListWorkspaces",
|
|
65
|
-
"/fonoster.identity.v1beta2.Identity/RefreshToken",
|
|
66
|
-
// Additional access here
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## ID, Access, and Refresh Tokens
|
|
72
|
-
|
|
73
|
-
The Identity module employs JSON Web Tokens (JWTs) for secure and flexible authentication. It strategically utilizes three types of tokens: ID, access, and refresh. Each token type serves a distinct purpose in the authentication process.
|
|
74
|
-
|
|
75
|
-
ID tokens identify the user and contain information about their identity. Typically short-lived, issued upon successful authentication. The following is an example of an ID token:
|
|
76
|
-
|
|
77
|
-
```json
|
|
78
|
-
{
|
|
79
|
-
"iss": "https://identity-global.fonoster.com",
|
|
80
|
-
"sub": "00000000-0000-0000-0000-000000000000",
|
|
81
|
-
"aud": "api",
|
|
82
|
-
"tokenUse": "id",
|
|
83
|
-
"accessKeyId": "US00000000000000000000000000000000",
|
|
84
|
-
"email": "johndoe@example.com",
|
|
85
|
-
"emailVerified": false,
|
|
86
|
-
"phoneNumber": null,
|
|
87
|
-
"phoneNumberVerified": false,
|
|
88
|
-
"iat": 1723477780,
|
|
89
|
-
"exp": 1723478680
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Access tokens enhance security with short lifespans (e.g., minutes to an 15m). They contain claims about the user or service, represented as a JSON object. The following is an example of an access token:
|
|
95
|
-
|
|
96
|
-
```json
|
|
97
|
-
{
|
|
98
|
-
"iss": "https://identity-global.fonoster.com",
|
|
99
|
-
"sub": "00000000-0000-0000-0000-000000000000",
|
|
100
|
-
"aud": "api",
|
|
101
|
-
"tokenUse": "access",
|
|
102
|
-
"accessKeyId": "US00000000000000000000000000000000",
|
|
103
|
-
"access": [
|
|
104
|
-
{
|
|
105
|
-
"accessKeyId": "WO00000000000000000000000000000000",
|
|
106
|
-
"role": "OWNER"
|
|
107
|
-
}
|
|
108
|
-
],
|
|
109
|
-
"iat": 1723477780,
|
|
110
|
-
"exp": 1723478680
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Here, `sub` is the user identifier, `aud` is the intended audience, and `access` contains a list of workspaces and their associated roles.
|
|
115
|
-
|
|
116
|
-
Refresh tokens have the specific function of obtaining new access tokens upon expiry. They possess longer lifespans than access tokens, potentially spanning days, weeks, or months, minimizing the frequency with which users need to re-enter their credentials. Due to their extended validity, refresh tokens warrant secure storage and careful management.
|
|
117
|
-
|
|
118
|
-
By default, refresh tokens are issued with a 24-hour expiration time. You can adjust this value to suit your security requirements.
|
|
119
|
-
|
|
120
|
-
An example of a refresh token:
|
|
121
|
-
|
|
122
|
-
```json
|
|
123
|
-
{
|
|
124
|
-
"iss": "https://identity-global.fonoster.com",
|
|
125
|
-
"sub": "00000000-0000-0000-0000-000000000000",
|
|
126
|
-
"aud": "api",
|
|
127
|
-
"tokenUse": "refresh",
|
|
128
|
-
"accessKeyId": "US00000000000000000000000000000000",
|
|
129
|
-
"iat": 1723477780,
|
|
130
|
-
"exp": 1723564180
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Like the access token, the `sub` is the user identifier, the `aud` is the intended audience.
|
|
135
|
-
|
|
136
|
-
## Token Exchange
|
|
137
|
-
|
|
138
|
-
The Identity module supports a variety of mechanisms to obtain initial access and refresh tokens. A conventional method involves a user supplying their username and password in exchange for an access token and a refresh token.
|
|
139
|
-
|
|
140
|
-
The module can enforce Multi-Factor Authentication (MFA) for enhanced security, requiring users to provide their username, password, and a time-based MFA code. Upon successful authentication, the module issues an access token and a refresh token.
|
|
141
|
-
|
|
142
|
-
The Identity module also supports OAuth2 code exchange, enabling integration with external identity providers. In this scenario, a user authenticates with the third-party provider and receives an authorization code to exchange with the Identity module for an access and refresh token.
|
|
143
|
-
|
|
144
|
-
The Identity Module simplifies the renewal process for expired access tokens. Users present a valid refresh token to receive a new access and refresh token pair. If your authentication strategy includes API keys, the module can also facilitate exchanging them for tokens.
|
|
145
|
-
|
|
146
|
-
## Refresh-Token Rotation Policy
|
|
147
|
-
|
|
148
|
-
Fonoster Identity uses a time-based refresh token, which means a refresh token will expire after a fixed amount of time. The Identity service must provide a mechanism to invalidate existing refresh tokens to address scenarios like compromised devices or accounts.
|
|
149
|
-
|
|
150
|
-
## Token Verification
|
|
151
|
-
|
|
152
|
-
The Identity module employs the RS256 algorithm to sign JWTs, guaranteeing their authenticity and integrity. A system can retrieve the public key from the issuer's `fonoster.identity.v1beta2.Identity.GetPublicKey` gRPC endpoint and use it to validate a token.
|
|
153
|
-
|
|
154
|
-
The verification process involves two steps: first, confirming the token's signature using the correct private key, and second, validating claims such as the issuer, intended audience, and expiration time to establish the token's overall validity.
|
|
155
|
-
|
|
156
|
-
> Fonoster's SDK must provide the necessary utility to automate this process
|
|
157
|
-
|
|
158
|
-
## Security Practices
|
|
159
|
-
|
|
160
|
-
To uphold security standards, Fonoster Identity mandates using HTTPS in all communications to safeguard tokens during transmission. We apply the principle of least privilege by granting tokens only the minimum permissions necessary to perform a specific task. We maintain comprehensive logging and monitoring of authentication events, token activities, and potential anomalies, essential for security auditing and swift incident response.
|
|
33
|
+
Proposed changes to this capability live under [`openspec/changes/`](../../openspec/changes).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
3
|
+
* http://github.com/fonoster/fonoster
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Fonoster
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the MIT License (the "License");
|
|
8
|
+
* you may not use this file except in compliance with
|
|
9
|
+
* the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://opensource.org/licenses/MIT
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* gRPC methods reachable without an access token. This is the single source of
|
|
21
|
+
* truth for Identity's public methods, shared by the standalone Identity service
|
|
22
|
+
* and the apiserver monolith (which appends its own non-identity entries).
|
|
23
|
+
*/
|
|
24
|
+
declare const identityAllowList: string[];
|
|
25
|
+
export { identityAllowList };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
4
|
+
* http://github.com/fonoster/fonoster
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Fonoster
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the MIT License (the "License");
|
|
9
|
+
* you may not use this file except in compliance with
|
|
10
|
+
* the License. You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* https://opensource.org/licenses/MIT
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.identityAllowList = void 0;
|
|
22
|
+
/**
|
|
23
|
+
* gRPC methods reachable without an access token. This is the single source of
|
|
24
|
+
* truth for Identity's public methods, shared by the standalone Identity service
|
|
25
|
+
* and the apiserver monolith (which appends its own non-identity entries).
|
|
26
|
+
*/
|
|
27
|
+
const identityAllowList = [
|
|
28
|
+
"/grpc.health.v1.Health/Check",
|
|
29
|
+
"/fonoster.identity.v1beta2.Identity/CreateUser",
|
|
30
|
+
"/fonoster.identity.v1beta2.Identity/CreateUserWithOauth2Code",
|
|
31
|
+
"/fonoster.identity.v1beta2.Identity/CreateWorkspace",
|
|
32
|
+
"/fonoster.identity.v1beta2.Identity/ExchangeApiKey",
|
|
33
|
+
"/fonoster.identity.v1beta2.Identity/ExchangeCredentials",
|
|
34
|
+
"/fonoster.identity.v1beta2.Identity/ExchangeOauth2Code",
|
|
35
|
+
"/fonoster.identity.v1beta2.Identity/ExchangeRefreshToken",
|
|
36
|
+
"/fonoster.identity.v1beta2.Identity/SendVerificationCode",
|
|
37
|
+
"/fonoster.identity.v1beta2.Identity/VerifyCode",
|
|
38
|
+
"/fonoster.identity.v1beta2.Identity/GetPublicKey",
|
|
39
|
+
"/fonoster.identity.v1beta2.Identity/SendResetPasswordCode",
|
|
40
|
+
"/fonoster.identity.v1beta2.Identity/ResetPassword"
|
|
41
|
+
];
|
|
42
|
+
exports.identityAllowList = identityAllowList;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
* See the License for the specific language governing permissions and
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
|
+
__exportStar(require("./allowList"), exports);
|
|
35
36
|
__exportStar(require("./apikeys"), exports);
|
|
36
37
|
__exportStar(require("./exchanges"), exports);
|
|
37
38
|
__exportStar(require("./invites"), exports);
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { IdentityConfig } from "../exchanges/types";
|
|
3
|
+
declare const identityServiceConfigSchema: z.ZodObject<{
|
|
4
|
+
server: z.ZodDefault<z.ZodObject<{
|
|
5
|
+
bindAddr: z.ZodDefault<z.ZodString>;
|
|
6
|
+
httpBridgePort: z.ZodDefault<z.ZodNumber>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
bindAddr?: string;
|
|
9
|
+
httpBridgePort?: number;
|
|
10
|
+
}, {
|
|
11
|
+
bindAddr?: string;
|
|
12
|
+
httpBridgePort?: number;
|
|
13
|
+
}>>;
|
|
14
|
+
database: z.ZodObject<{
|
|
15
|
+
url: z.ZodString;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
url?: string;
|
|
18
|
+
}, {
|
|
19
|
+
url?: string;
|
|
20
|
+
}>;
|
|
21
|
+
encryptionKey: z.ZodString;
|
|
22
|
+
issuer: z.ZodString;
|
|
23
|
+
audience: z.ZodString;
|
|
24
|
+
keys: z.ZodEffects<z.ZodObject<{
|
|
25
|
+
privateKey: z.ZodOptional<z.ZodString>;
|
|
26
|
+
publicKey: z.ZodOptional<z.ZodString>;
|
|
27
|
+
privateKeyPath: z.ZodOptional<z.ZodString>;
|
|
28
|
+
publicKeyPath: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
privateKey?: string;
|
|
31
|
+
publicKey?: string;
|
|
32
|
+
privateKeyPath?: string;
|
|
33
|
+
publicKeyPath?: string;
|
|
34
|
+
}, {
|
|
35
|
+
privateKey?: string;
|
|
36
|
+
publicKey?: string;
|
|
37
|
+
privateKeyPath?: string;
|
|
38
|
+
publicKeyPath?: string;
|
|
39
|
+
}>, {
|
|
40
|
+
privateKey?: string;
|
|
41
|
+
publicKey?: string;
|
|
42
|
+
privateKeyPath?: string;
|
|
43
|
+
publicKeyPath?: string;
|
|
44
|
+
}, {
|
|
45
|
+
privateKey?: string;
|
|
46
|
+
publicKey?: string;
|
|
47
|
+
privateKeyPath?: string;
|
|
48
|
+
publicKeyPath?: string;
|
|
49
|
+
}>;
|
|
50
|
+
tokens: z.ZodDefault<z.ZodObject<{
|
|
51
|
+
accessTokenExpiresIn: z.ZodDefault<z.ZodString>;
|
|
52
|
+
refreshTokenExpiresIn: z.ZodDefault<z.ZodString>;
|
|
53
|
+
idTokenExpiresIn: z.ZodDefault<z.ZodString>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
idTokenExpiresIn?: string;
|
|
56
|
+
accessTokenExpiresIn?: string;
|
|
57
|
+
refreshTokenExpiresIn?: string;
|
|
58
|
+
}, {
|
|
59
|
+
idTokenExpiresIn?: string;
|
|
60
|
+
accessTokenExpiresIn?: string;
|
|
61
|
+
refreshTokenExpiresIn?: string;
|
|
62
|
+
}>>;
|
|
63
|
+
security: z.ZodDefault<z.ZodObject<{
|
|
64
|
+
contactVerificationRequired: z.ZodDefault<z.ZodBoolean>;
|
|
65
|
+
twoFactorAuthenticationRequired: z.ZodDefault<z.ZodBoolean>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
contactVerificationRequired?: boolean;
|
|
68
|
+
twoFactorAuthenticationRequired?: boolean;
|
|
69
|
+
}, {
|
|
70
|
+
contactVerificationRequired?: boolean;
|
|
71
|
+
twoFactorAuthenticationRequired?: boolean;
|
|
72
|
+
}>>;
|
|
73
|
+
invite: z.ZodDefault<z.ZodObject<{
|
|
74
|
+
url: z.ZodDefault<z.ZodString>;
|
|
75
|
+
failUrl: z.ZodDefault<z.ZodString>;
|
|
76
|
+
expiration: z.ZodDefault<z.ZodString>;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
url?: string;
|
|
79
|
+
failUrl?: string;
|
|
80
|
+
expiration?: string;
|
|
81
|
+
}, {
|
|
82
|
+
url?: string;
|
|
83
|
+
failUrl?: string;
|
|
84
|
+
expiration?: string;
|
|
85
|
+
}>>;
|
|
86
|
+
appUrl: z.ZodDefault<z.ZodString>;
|
|
87
|
+
smtp: z.ZodOptional<z.ZodObject<{
|
|
88
|
+
host: z.ZodString;
|
|
89
|
+
port: z.ZodNumber;
|
|
90
|
+
secure: z.ZodDefault<z.ZodBoolean>;
|
|
91
|
+
sender: z.ZodString;
|
|
92
|
+
auth: z.ZodDefault<z.ZodObject<{
|
|
93
|
+
user: z.ZodDefault<z.ZodString>;
|
|
94
|
+
pass: z.ZodDefault<z.ZodString>;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
user?: string;
|
|
97
|
+
pass?: string;
|
|
98
|
+
}, {
|
|
99
|
+
user?: string;
|
|
100
|
+
pass?: string;
|
|
101
|
+
}>>;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
host?: string;
|
|
104
|
+
port?: number;
|
|
105
|
+
secure?: boolean;
|
|
106
|
+
sender?: string;
|
|
107
|
+
auth?: {
|
|
108
|
+
user?: string;
|
|
109
|
+
pass?: string;
|
|
110
|
+
};
|
|
111
|
+
}, {
|
|
112
|
+
host?: string;
|
|
113
|
+
port?: number;
|
|
114
|
+
secure?: boolean;
|
|
115
|
+
sender?: string;
|
|
116
|
+
auth?: {
|
|
117
|
+
user?: string;
|
|
118
|
+
pass?: string;
|
|
119
|
+
};
|
|
120
|
+
}>>;
|
|
121
|
+
oauth2: z.ZodOptional<z.ZodObject<{
|
|
122
|
+
github: z.ZodObject<{
|
|
123
|
+
clientId: z.ZodString;
|
|
124
|
+
clientSecret: z.ZodString;
|
|
125
|
+
}, "strip", z.ZodTypeAny, {
|
|
126
|
+
clientId?: string;
|
|
127
|
+
clientSecret?: string;
|
|
128
|
+
}, {
|
|
129
|
+
clientId?: string;
|
|
130
|
+
clientSecret?: string;
|
|
131
|
+
}>;
|
|
132
|
+
}, "strip", z.ZodTypeAny, {
|
|
133
|
+
github?: {
|
|
134
|
+
clientId?: string;
|
|
135
|
+
clientSecret?: string;
|
|
136
|
+
};
|
|
137
|
+
}, {
|
|
138
|
+
github?: {
|
|
139
|
+
clientId?: string;
|
|
140
|
+
clientSecret?: string;
|
|
141
|
+
};
|
|
142
|
+
}>>;
|
|
143
|
+
defaultUser: z.ZodOptional<z.ZodObject<{
|
|
144
|
+
name: z.ZodString;
|
|
145
|
+
email: z.ZodString;
|
|
146
|
+
password: z.ZodString;
|
|
147
|
+
}, "strip", z.ZodTypeAny, {
|
|
148
|
+
name?: string;
|
|
149
|
+
email?: string;
|
|
150
|
+
password?: string;
|
|
151
|
+
}, {
|
|
152
|
+
name?: string;
|
|
153
|
+
email?: string;
|
|
154
|
+
password?: string;
|
|
155
|
+
}>>;
|
|
156
|
+
}, "strip", z.ZodTypeAny, {
|
|
157
|
+
keys?: {
|
|
158
|
+
privateKey?: string;
|
|
159
|
+
publicKey?: string;
|
|
160
|
+
privateKeyPath?: string;
|
|
161
|
+
publicKeyPath?: string;
|
|
162
|
+
};
|
|
163
|
+
issuer?: string;
|
|
164
|
+
audience?: string;
|
|
165
|
+
server?: {
|
|
166
|
+
bindAddr?: string;
|
|
167
|
+
httpBridgePort?: number;
|
|
168
|
+
};
|
|
169
|
+
database?: {
|
|
170
|
+
url?: string;
|
|
171
|
+
};
|
|
172
|
+
encryptionKey?: string;
|
|
173
|
+
tokens?: {
|
|
174
|
+
idTokenExpiresIn?: string;
|
|
175
|
+
accessTokenExpiresIn?: string;
|
|
176
|
+
refreshTokenExpiresIn?: string;
|
|
177
|
+
};
|
|
178
|
+
security?: {
|
|
179
|
+
contactVerificationRequired?: boolean;
|
|
180
|
+
twoFactorAuthenticationRequired?: boolean;
|
|
181
|
+
};
|
|
182
|
+
invite?: {
|
|
183
|
+
url?: string;
|
|
184
|
+
failUrl?: string;
|
|
185
|
+
expiration?: string;
|
|
186
|
+
};
|
|
187
|
+
appUrl?: string;
|
|
188
|
+
smtp?: {
|
|
189
|
+
host?: string;
|
|
190
|
+
port?: number;
|
|
191
|
+
secure?: boolean;
|
|
192
|
+
sender?: string;
|
|
193
|
+
auth?: {
|
|
194
|
+
user?: string;
|
|
195
|
+
pass?: string;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
oauth2?: {
|
|
199
|
+
github?: {
|
|
200
|
+
clientId?: string;
|
|
201
|
+
clientSecret?: string;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
defaultUser?: {
|
|
205
|
+
name?: string;
|
|
206
|
+
email?: string;
|
|
207
|
+
password?: string;
|
|
208
|
+
};
|
|
209
|
+
}, {
|
|
210
|
+
keys?: {
|
|
211
|
+
privateKey?: string;
|
|
212
|
+
publicKey?: string;
|
|
213
|
+
privateKeyPath?: string;
|
|
214
|
+
publicKeyPath?: string;
|
|
215
|
+
};
|
|
216
|
+
issuer?: string;
|
|
217
|
+
audience?: string;
|
|
218
|
+
server?: {
|
|
219
|
+
bindAddr?: string;
|
|
220
|
+
httpBridgePort?: number;
|
|
221
|
+
};
|
|
222
|
+
database?: {
|
|
223
|
+
url?: string;
|
|
224
|
+
};
|
|
225
|
+
encryptionKey?: string;
|
|
226
|
+
tokens?: {
|
|
227
|
+
idTokenExpiresIn?: string;
|
|
228
|
+
accessTokenExpiresIn?: string;
|
|
229
|
+
refreshTokenExpiresIn?: string;
|
|
230
|
+
};
|
|
231
|
+
security?: {
|
|
232
|
+
contactVerificationRequired?: boolean;
|
|
233
|
+
twoFactorAuthenticationRequired?: boolean;
|
|
234
|
+
};
|
|
235
|
+
invite?: {
|
|
236
|
+
url?: string;
|
|
237
|
+
failUrl?: string;
|
|
238
|
+
expiration?: string;
|
|
239
|
+
};
|
|
240
|
+
appUrl?: string;
|
|
241
|
+
smtp?: {
|
|
242
|
+
host?: string;
|
|
243
|
+
port?: number;
|
|
244
|
+
secure?: boolean;
|
|
245
|
+
sender?: string;
|
|
246
|
+
auth?: {
|
|
247
|
+
user?: string;
|
|
248
|
+
pass?: string;
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
oauth2?: {
|
|
252
|
+
github?: {
|
|
253
|
+
clientId?: string;
|
|
254
|
+
clientSecret?: string;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
defaultUser?: {
|
|
258
|
+
name?: string;
|
|
259
|
+
email?: string;
|
|
260
|
+
password?: string;
|
|
261
|
+
};
|
|
262
|
+
}>;
|
|
263
|
+
type IdentityServiceConfig = z.infer<typeof identityServiceConfigSchema>;
|
|
264
|
+
/** Loads and validates the service configuration from the file, failing fast. */
|
|
265
|
+
declare function loadConfig(argv?: string[]): {
|
|
266
|
+
bindAddr: string;
|
|
267
|
+
httpBridgePort: number;
|
|
268
|
+
appUrl: string;
|
|
269
|
+
defaultUser: {
|
|
270
|
+
name?: string;
|
|
271
|
+
email?: string;
|
|
272
|
+
password?: string;
|
|
273
|
+
};
|
|
274
|
+
identityConfig: IdentityConfig;
|
|
275
|
+
};
|
|
276
|
+
export { identityServiceConfigSchema, IdentityServiceConfig, loadConfig };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.identityServiceConfigSchema = void 0;
|
|
4
|
+
exports.loadConfig = loadConfig;
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
7
|
+
* http://github.com/fonoster/fonoster
|
|
8
|
+
*
|
|
9
|
+
* This file is part of Fonoster
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the MIT License (the "License");
|
|
12
|
+
* you may not use this file except in compliance with
|
|
13
|
+
* the License. You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* https://opensource.org/licenses/MIT
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
const fs_1 = require("fs");
|
|
24
|
+
const path_1 = require("path");
|
|
25
|
+
const zod_1 = require("zod");
|
|
26
|
+
const zod_validation_error_1 = require("zod-validation-error");
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for the standalone Identity service.
|
|
29
|
+
*
|
|
30
|
+
* The service is configured exclusively from a JSON configuration file — no
|
|
31
|
+
* environment variables. The file path is taken from a `--config <path>` CLI
|
|
32
|
+
* flag, defaulting to `./config/identity.json` relative to the working
|
|
33
|
+
* directory.
|
|
34
|
+
*/
|
|
35
|
+
const keysSchema = zod_1.z
|
|
36
|
+
.object({
|
|
37
|
+
privateKey: zod_1.z.string().optional(),
|
|
38
|
+
publicKey: zod_1.z.string().optional(),
|
|
39
|
+
privateKeyPath: zod_1.z.string().optional(),
|
|
40
|
+
publicKeyPath: zod_1.z.string().optional()
|
|
41
|
+
})
|
|
42
|
+
.refine((k) => (k.privateKey || k.privateKeyPath) && (k.publicKey || k.publicKeyPath), {
|
|
43
|
+
message: "keys must provide a private and public key, inline or by path"
|
|
44
|
+
});
|
|
45
|
+
const smtpSchema = zod_1.z.object({
|
|
46
|
+
host: zod_1.z.string(),
|
|
47
|
+
port: zod_1.z.number(),
|
|
48
|
+
secure: zod_1.z.boolean().default(false),
|
|
49
|
+
sender: zod_1.z.string(),
|
|
50
|
+
auth: zod_1.z
|
|
51
|
+
.object({ user: zod_1.z.string().default(""), pass: zod_1.z.string().default("") })
|
|
52
|
+
.default({})
|
|
53
|
+
});
|
|
54
|
+
const identityServiceConfigSchema = zod_1.z.object({
|
|
55
|
+
server: zod_1.z
|
|
56
|
+
.object({
|
|
57
|
+
bindAddr: zod_1.z.string().default("0.0.0.0:50051"),
|
|
58
|
+
httpBridgePort: zod_1.z.number().default(9000)
|
|
59
|
+
})
|
|
60
|
+
.default({}),
|
|
61
|
+
database: zod_1.z.object({ url: zod_1.z.string().min(1) }),
|
|
62
|
+
encryptionKey: zod_1.z.string().min(1),
|
|
63
|
+
issuer: zod_1.z.string().min(1),
|
|
64
|
+
audience: zod_1.z.string().min(1),
|
|
65
|
+
keys: keysSchema,
|
|
66
|
+
tokens: zod_1.z
|
|
67
|
+
.object({
|
|
68
|
+
accessTokenExpiresIn: zod_1.z.string().default("15m"),
|
|
69
|
+
refreshTokenExpiresIn: zod_1.z.string().default("30d"),
|
|
70
|
+
idTokenExpiresIn: zod_1.z.string().default("15m")
|
|
71
|
+
})
|
|
72
|
+
.default({}),
|
|
73
|
+
security: zod_1.z
|
|
74
|
+
.object({
|
|
75
|
+
contactVerificationRequired: zod_1.z.boolean().default(false),
|
|
76
|
+
twoFactorAuthenticationRequired: zod_1.z.boolean().default(false)
|
|
77
|
+
})
|
|
78
|
+
.default({}),
|
|
79
|
+
invite: zod_1.z
|
|
80
|
+
.object({
|
|
81
|
+
url: zod_1.z.string().default(""),
|
|
82
|
+
failUrl: zod_1.z.string().default(""),
|
|
83
|
+
expiration: zod_1.z.string().default("2d")
|
|
84
|
+
})
|
|
85
|
+
.default({}),
|
|
86
|
+
appUrl: zod_1.z.string().default(""),
|
|
87
|
+
smtp: smtpSchema.optional(),
|
|
88
|
+
oauth2: zod_1.z
|
|
89
|
+
.object({
|
|
90
|
+
github: zod_1.z.object({ clientId: zod_1.z.string(), clientSecret: zod_1.z.string() })
|
|
91
|
+
})
|
|
92
|
+
.optional(),
|
|
93
|
+
defaultUser: zod_1.z
|
|
94
|
+
.object({
|
|
95
|
+
name: zod_1.z.string(),
|
|
96
|
+
email: zod_1.z.string().email(),
|
|
97
|
+
password: zod_1.z.string()
|
|
98
|
+
})
|
|
99
|
+
.optional()
|
|
100
|
+
});
|
|
101
|
+
exports.identityServiceConfigSchema = identityServiceConfigSchema;
|
|
102
|
+
function configPathFromArgv(argv) {
|
|
103
|
+
const i = argv.indexOf("--config");
|
|
104
|
+
const fromFlag = i >= 0 ? argv[i + 1] : undefined;
|
|
105
|
+
return (0, path_1.resolve)(process.cwd(), fromFlag !== null && fromFlag !== void 0 ? fromFlag : "./config/identity.json");
|
|
106
|
+
}
|
|
107
|
+
function readKey(inline, path) {
|
|
108
|
+
return inline !== null && inline !== void 0 ? inline : (0, fs_1.readFileSync)((0, path_1.resolve)(process.cwd(), path), "utf8");
|
|
109
|
+
}
|
|
110
|
+
/** Maps the file config into the `IdentityConfig` shape `buildIdentityService` expects. */
|
|
111
|
+
function toIdentityConfig(c) {
|
|
112
|
+
var _a;
|
|
113
|
+
return {
|
|
114
|
+
dbUrl: c.database.url,
|
|
115
|
+
issuer: c.issuer,
|
|
116
|
+
audience: c.audience,
|
|
117
|
+
privateKey: readKey(c.keys.privateKey, c.keys.privateKeyPath),
|
|
118
|
+
publicKey: readKey(c.keys.publicKey, c.keys.publicKeyPath),
|
|
119
|
+
encryptionKey: c.encryptionKey,
|
|
120
|
+
accessTokenExpiresIn: c.tokens.accessTokenExpiresIn,
|
|
121
|
+
refreshTokenExpiresIn: c.tokens.refreshTokenExpiresIn,
|
|
122
|
+
idTokenExpiresIn: c.tokens.idTokenExpiresIn,
|
|
123
|
+
workspaceInviteExpiration: c.invite.expiration,
|
|
124
|
+
workspaceInviteUrl: c.invite.url,
|
|
125
|
+
workspaceInviteFailUrl: c.invite.failUrl,
|
|
126
|
+
contactVerificationRequired: c.security.contactVerificationRequired,
|
|
127
|
+
twoFactorAuthenticationRequired: c.security.twoFactorAuthenticationRequired,
|
|
128
|
+
smtpConfig: c.smtp,
|
|
129
|
+
githubOauth2Config: (_a = c.oauth2) === null || _a === void 0 ? void 0 : _a.github
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Loads and validates the service configuration from the file, failing fast. */
|
|
133
|
+
function loadConfig(argv = process.argv) {
|
|
134
|
+
const path = configPathFromArgv(argv);
|
|
135
|
+
let raw;
|
|
136
|
+
try {
|
|
137
|
+
raw = JSON.parse((0, fs_1.readFileSync)(path, "utf8"));
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
throw new Error(`unable to read Identity config at ${path}: ${e.message}`);
|
|
141
|
+
}
|
|
142
|
+
const result = identityServiceConfigSchema.safeParse(raw);
|
|
143
|
+
if (!result.success) {
|
|
144
|
+
throw new Error(`invalid Identity config at ${path}: ${(0, zod_validation_error_1.fromError)(result.error).toString()}`);
|
|
145
|
+
}
|
|
146
|
+
const config = result.data;
|
|
147
|
+
return {
|
|
148
|
+
bindAddr: config.server.bindAddr,
|
|
149
|
+
httpBridgePort: config.server.httpBridgePort,
|
|
150
|
+
appUrl: config.appUrl,
|
|
151
|
+
defaultUser: config.defaultUser,
|
|
152
|
+
identityConfig: toIdentityConfig(config)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IdentityConfig } from "../exchanges/types";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal HTTP bridge for the standalone Identity service. It serves only the
|
|
4
|
+
* accept-invite endpoint (the apiserver's bridge also serves telephony routes).
|
|
5
|
+
*/
|
|
6
|
+
declare function startHttpBridge(identityConfig: IdentityConfig, params: {
|
|
7
|
+
port: number;
|
|
8
|
+
appUrl: string;
|
|
9
|
+
}): import("express-serve-static-core").Express;
|
|
10
|
+
export { startHttpBridge };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.startHttpBridge = startHttpBridge;
|
|
16
|
+
/**
|
|
17
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
18
|
+
* http://github.com/fonoster/fonoster
|
|
19
|
+
*
|
|
20
|
+
* This file is part of Fonoster
|
|
21
|
+
*
|
|
22
|
+
* Licensed under the MIT License (the "License");
|
|
23
|
+
* you may not use this file except in compliance with
|
|
24
|
+
* the License. You may obtain a copy of the License at
|
|
25
|
+
*
|
|
26
|
+
* https://opensource.org/licenses/MIT
|
|
27
|
+
*
|
|
28
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
30
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
31
|
+
* See the License for the specific language governing permissions and
|
|
32
|
+
* limitations under the License.
|
|
33
|
+
*/
|
|
34
|
+
const logger_1 = require("@fonoster/logger");
|
|
35
|
+
const express_1 = __importDefault(require("express"));
|
|
36
|
+
const utils_1 = require("../utils");
|
|
37
|
+
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
38
|
+
/**
|
|
39
|
+
* Minimal HTTP bridge for the standalone Identity service. It serves only the
|
|
40
|
+
* accept-invite endpoint (the apiserver's bridge also serves telephony routes).
|
|
41
|
+
*/
|
|
42
|
+
function startHttpBridge(identityConfig, params) {
|
|
43
|
+
const { port, appUrl } = params;
|
|
44
|
+
const app = (0, express_1.default)();
|
|
45
|
+
app.get("/api/identity/accept-invite", (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
try {
|
|
47
|
+
yield (0, utils_1.createUpdateMembershipStatus)(identityConfig)(req.query.token);
|
|
48
|
+
res.redirect(appUrl);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
logger.verbose("error updating membership status", error);
|
|
52
|
+
res.redirect(identityConfig.workspaceInviteFailUrl);
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
app.listen(port, () => {
|
|
56
|
+
logger.info(`Identity HTTP bridge running on port ${port}`);
|
|
57
|
+
});
|
|
58
|
+
return app;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
/**
|
|
46
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
47
|
+
* http://github.com/fonoster/fonoster
|
|
48
|
+
*
|
|
49
|
+
* This file is part of Fonoster
|
|
50
|
+
*
|
|
51
|
+
* Licensed under the MIT License (the "License");
|
|
52
|
+
* you may not use this file except in compliance with
|
|
53
|
+
* the License. You may obtain a copy of the License at
|
|
54
|
+
*
|
|
55
|
+
* https://opensource.org/licenses/MIT
|
|
56
|
+
*
|
|
57
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
58
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
59
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
60
|
+
* See the License for the specific language governing permissions and
|
|
61
|
+
* limitations under the License.
|
|
62
|
+
*/
|
|
63
|
+
const common_1 = require("@fonoster/common");
|
|
64
|
+
const logger_1 = require("@fonoster/logger");
|
|
65
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
66
|
+
const grpc_health_check_1 = require("grpc-health-check");
|
|
67
|
+
const __1 = require("..");
|
|
68
|
+
const config_1 = require("./config");
|
|
69
|
+
const httpBridge_1 = require("./httpBridge");
|
|
70
|
+
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
71
|
+
/**
|
|
72
|
+
* Standalone Identity gRPC service. Wraps `buildIdentityService` with the auth
|
|
73
|
+
* interceptor, the identity allow-list, a health service, and the accept-invite
|
|
74
|
+
* HTTP bridge — without any telephony subsystem. Configured entirely from a
|
|
75
|
+
* file (see `./config`); no environment variables.
|
|
76
|
+
*/
|
|
77
|
+
function main() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const { bindAddr, httpBridgePort, appUrl, defaultUser, identityConfig } = (0, config_1.loadConfig)();
|
|
80
|
+
const { definition, handlers } = (0, __1.buildIdentityService)(identityConfig);
|
|
81
|
+
const authorization = (0, common_1.createAuthInterceptor)(identityConfig.publicKey, __1.identityAllowList);
|
|
82
|
+
const credentials = yield (0, common_1.getServerCredentials)({});
|
|
83
|
+
const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
|
|
84
|
+
const server = new grpc.Server({ interceptors: [authorization] });
|
|
85
|
+
healthImpl.addToServer(server);
|
|
86
|
+
server.addService((0, common_1.createServiceDefinition)(definition), handlers);
|
|
87
|
+
if (defaultUser) {
|
|
88
|
+
yield (0, __1.upsertDefaultUser)(identityConfig, defaultUser);
|
|
89
|
+
}
|
|
90
|
+
(0, httpBridge_1.startHttpBridge)(identityConfig, { port: httpBridgePort, appUrl });
|
|
91
|
+
server.bindAsync(bindAddr, credentials, (error) => {
|
|
92
|
+
if (error) {
|
|
93
|
+
logger.error("failed to start Identity service", error);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
healthImpl.setStatus("", common_1.GRPC_SERVING_STATUS);
|
|
97
|
+
logger.info(`Identity service running at ${bindAddr}`);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
main().catch((error) => {
|
|
102
|
+
logger.error(error);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "Identity service for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -14,17 +14,22 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
16
16
|
"build": "tsc -b tsconfig.json",
|
|
17
|
+
"start": "node dist/server/index.js",
|
|
18
|
+
"db:deploy": "node scripts/db-provision.mjs",
|
|
17
19
|
"clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
|
|
18
20
|
},
|
|
19
21
|
"bin": {
|
|
20
|
-
"fonoster": "./dist/index.js"
|
|
22
|
+
"fonoster": "./dist/index.js",
|
|
23
|
+
"fonoster-identity": "./dist/server/index.js"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
|
-
"@fonoster/common": "^0.
|
|
24
|
-
"@fonoster/logger": "^0.
|
|
25
|
-
"@fonoster/types": "^0.
|
|
26
|
+
"@fonoster/common": "^0.19.1",
|
|
27
|
+
"@fonoster/logger": "^0.19.1",
|
|
28
|
+
"@fonoster/types": "^0.19.1",
|
|
26
29
|
"@grpc/grpc-js": "~1.10.6",
|
|
27
30
|
"@prisma/client": "^6.8.2",
|
|
31
|
+
"express": "^5.0.1",
|
|
32
|
+
"grpc-health-check": "^2.0.1",
|
|
28
33
|
"jsonwebtoken": "^9.0.2",
|
|
29
34
|
"jwt-decode": "^4.0.0",
|
|
30
35
|
"nanoid": "^3.3.6",
|
|
@@ -46,7 +51,9 @@
|
|
|
46
51
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
47
52
|
},
|
|
48
53
|
"devDependencies": {
|
|
49
|
-
"@types/
|
|
54
|
+
"@types/express": "^5.0.6",
|
|
55
|
+
"@types/jsonwebtoken": "^9.0.6",
|
|
56
|
+
"prisma": "^6.8.2"
|
|
50
57
|
},
|
|
51
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "4c28def9ff1aebbbaf2e23a8944cf3cf49c4da1e"
|
|
52
59
|
}
|