@fonoster/identity 0.18.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Discord](https://img.shields.io/discord/1016419835455996076?color=5865F2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/4QWgSz4hTC) ![GitHub](https://img.shields.io/github/license/fonoster/fonoster?color=%2347b96d) ![Twitter Follow](https://img.shields.io/twitter/follow/fonoster?style=social)
2
2
 
3
- This document provides a high-level overview of the Identity module, which is helpful for maintainers, contributors, and developers who want to understand its architecture and design or contribute to it.
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 provide a way to organize users and streamline permission administration logically. A user can belong to multiple 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
- The Identity module ensures secure authentication by employing industry-standard JSON Web Tokens (JWTs). It supports a variety of authentication mechanisms, including username and password, Multi-Factor Authentication (MFA) for added security, OAuth2 for integration with external identity providers, and token exchange to accommodate diverse scenarios.
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
- Authorization is implemented through a Role-Based Access Control (RBAC) model, allowing for granular control over user and service actions. Predefined roles offer convenience, while the option to create custom roles provides maximum flexibility.
25
+ ## Specification
24
26
 
25
- ## Users, Workspaces, and Roles
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
- Individual users or services connecting to the Identity service will require a Role. As you will see in the next section, a Role has a set of allowed actions.
31
+ ➡️ [`openspec/specs/identity/spec.md`](../../openspec/specs/identity/spec.md)
28
32
 
29
- Take the following example:
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;
@@ -36,11 +36,11 @@ exports.Prisma = Prisma
36
36
  exports.$Enums = {}
37
37
 
38
38
  /**
39
- * Prisma Client JS version: 6.19.1
39
+ * Prisma Client JS version: 6.19.2
40
40
  * Query Engine version: c2990dca591cba766e3b7ef5d9e8a84796e47ab7
41
41
  */
42
42
  Prisma.prismaVersion = {
43
- client: "6.19.1",
43
+ client: "6.19.2",
44
44
  engine: "c2990dca591cba766e3b7ef5d9e8a84796e47ab7"
45
45
  }
46
46
 
@@ -228,7 +228,7 @@ const config = {
228
228
  "rootEnvPath": null
229
229
  },
230
230
  "relativePath": "../../../..",
231
- "clientVersion": "6.19.1",
231
+ "clientVersion": "6.19.2",
232
232
  "engineVersion": "c2990dca591cba766e3b7ef5d9e8a84796e47ab7",
233
233
  "datasourceNames": [
234
234
  "db"
@@ -21,11 +21,11 @@ exports.Prisma = Prisma
21
21
  exports.$Enums = {}
22
22
 
23
23
  /**
24
- * Prisma Client JS version: 6.19.1
24
+ * Prisma Client JS version: 6.19.2
25
25
  * Query Engine version: c2990dca591cba766e3b7ef5d9e8a84796e47ab7
26
26
  */
27
27
  Prisma.prismaVersion = {
28
- client: "6.19.1",
28
+ client: "6.19.2",
29
29
  engine: "c2990dca591cba766e3b7ef5d9e8a84796e47ab7"
30
30
  }
31
31
 
@@ -307,7 +307,7 @@ export namespace Prisma {
307
307
  export import Exact = $Public.Exact
308
308
 
309
309
  /**
310
- * Prisma Client JS version: 6.19.1
310
+ * Prisma Client JS version: 6.19.2
311
311
  * Query Engine version: c2990dca591cba766e3b7ef5d9e8a84796e47ab7
312
312
  */
313
313
  export type PrismaVersion = {
@@ -36,11 +36,11 @@ exports.Prisma = Prisma
36
36
  exports.$Enums = {}
37
37
 
38
38
  /**
39
- * Prisma Client JS version: 6.19.1
39
+ * Prisma Client JS version: 6.19.2
40
40
  * Query Engine version: c2990dca591cba766e3b7ef5d9e8a84796e47ab7
41
41
  */
42
42
  Prisma.prismaVersion = {
43
- client: "6.19.1",
43
+ client: "6.19.2",
44
44
  engine: "c2990dca591cba766e3b7ef5d9e8a84796e47ab7"
45
45
  }
46
46
 
@@ -229,7 +229,7 @@ const config = {
229
229
  "rootEnvPath": null
230
230
  },
231
231
  "relativePath": "../../../..",
232
- "clientVersion": "6.19.1",
232
+ "clientVersion": "6.19.2",
233
233
  "engineVersion": "c2990dca591cba766e3b7ef5d9e8a84796e47ab7",
234
234
  "datasourceNames": [
235
235
  "db"
@@ -151,7 +151,7 @@
151
151
  },
152
152
  "./*": "./*"
153
153
  },
154
- "version": "6.19.1",
154
+ "version": "6.19.2",
155
155
  "sideEffects": false,
156
156
  "imports": {
157
157
  "#wasm-engine-loader": {