docpouch-client 0.9.1 → 1.0.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 +630 -449
- package/chat-09e440bd-c52c-44b9-bba4-01cebc84bd7b.txt +223 -0
- package/dist/index.d.ts +146 -5
- package/dist/index.js +308 -10
- package/{jest.config.js → jest.config.cjs} +1 -1
- package/package.json +41 -38
- package/src/index.ts +1003 -622
- package/tests/docPouchClient.test.ts +654 -0
- package/tests/mock-server.ts +613 -0
- package/tsconfig.build.json +7 -0
- package/tsconfig.json +9 -7
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Chat 'ChatTitle(text="I am adding authent…" with OpenCode, isCustom=true)' (09e440bd-c52c-44b9-bba4-01cebc84bd7b)
|
|
2
|
+
Context:
|
|
3
|
+
|
|
4
|
+
Messages: 18
|
|
5
|
+
=================================================================================================================
|
|
6
|
+
|
|
7
|
+
==== RestoredMessage #1 ====
|
|
8
|
+
User:
|
|
9
|
+
I am adding authentication using node-oidcProvider to my app in addition to the already present localStorage solution. To give clients the possibility to register, is it enough to create a call to `this.expressApp.post` and get the necessary information from the client including some kind of secret?
|
|
10
|
+
Attachments:
|
|
11
|
+
Attachment Name: Console Selection
|
|
12
|
+
Attachments Kind: Visible
|
|
13
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
14
|
+
Attachments Text:
|
|
15
|
+
this.expressApp.get
|
|
16
|
+
Attachment Name: Console Selection
|
|
17
|
+
Attachments Kind: Visible
|
|
18
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
19
|
+
Attachments Text:
|
|
20
|
+
validate
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
kotlin.Unit
|
|
24
|
+
|
|
25
|
+
==== RestoredMessage #2 ====
|
|
26
|
+
Assistant:
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
kotlin.Unit
|
|
30
|
+
|
|
31
|
+
==== RestoredMessage #3 ====
|
|
32
|
+
User:
|
|
33
|
+
Yes, good idea
|
|
34
|
+
Attachments:
|
|
35
|
+
Attachment Name: Console Selection
|
|
36
|
+
Attachments Kind: Visible
|
|
37
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
38
|
+
Attachments Text:
|
|
39
|
+
validate
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
kotlin.Unit
|
|
43
|
+
|
|
44
|
+
==== RestoredMessage #4 ====
|
|
45
|
+
Assistant:
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
kotlin.Unit
|
|
49
|
+
|
|
50
|
+
==== RestoredMessage #5 ====
|
|
51
|
+
User:
|
|
52
|
+
1. I want a controlled registration. I changed initialAccessToken to `process.env.OIDC_REGISTRATION_TOKEN`.
|
|
53
|
+
2. I don't even know what JWKS is, let alone have anything set up for it.
|
|
54
|
+
Yes, please proceed
|
|
55
|
+
Attachments:
|
|
56
|
+
Attachment Name: Console Selection
|
|
57
|
+
Attachments Kind: Visible
|
|
58
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
59
|
+
Attachments Text:
|
|
60
|
+
process.env.OIDC_REGISTRATION_TOKEN
|
|
61
|
+
Attachment Name: Console Selection
|
|
62
|
+
Attachments Kind: Visible
|
|
63
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
64
|
+
Attachments Text:
|
|
65
|
+
validate
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
kotlin.Unit
|
|
69
|
+
|
|
70
|
+
==== RestoredMessage #6 ====
|
|
71
|
+
Assistant:
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
kotlin.Unit
|
|
75
|
+
|
|
76
|
+
==== RestoredMessage #7 ====
|
|
77
|
+
User:
|
|
78
|
+
Let's go with a static JWKS for starters. Yes, I would like the clients to have their choice, whether they want to use the localStorage or the OIDC approach for authentication. For both, the clients are expected to build their own login masks.
|
|
79
|
+
If the registration token is not just a random string, I need help, yes.
|
|
80
|
+
Attachments:
|
|
81
|
+
Attachment Name: Console Selection
|
|
82
|
+
Attachments Kind: Visible
|
|
83
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
84
|
+
Attachments Text:
|
|
85
|
+
process.env.OIDC_REGISTRATION_TOKEN
|
|
86
|
+
Attachment Name: Console Selection
|
|
87
|
+
Attachments Kind: Visible
|
|
88
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
89
|
+
Attachments Text:
|
|
90
|
+
validate
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
kotlin.Unit
|
|
94
|
+
|
|
95
|
+
==== RestoredMessage #8 ====
|
|
96
|
+
Assistant:
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
kotlin.Unit
|
|
100
|
+
|
|
101
|
+
==== RestoredMessage #9 ====
|
|
102
|
+
User:
|
|
103
|
+
I am unsure,now. If I give clients these options for auth, is it easier for them, than having to build their own login mask?
|
|
104
|
+
1. The old approach using the token in localStorage.
|
|
105
|
+
2. OIDC and they can use a login mask provided by docPouch.
|
|
106
|
+
Attachments:
|
|
107
|
+
Attachment Name: Console Selection
|
|
108
|
+
Attachments Kind: Visible
|
|
109
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
110
|
+
Attachments Text:
|
|
111
|
+
process.env.OIDC_REGISTRATION_TOKEN
|
|
112
|
+
Attachment Name: Console Selection
|
|
113
|
+
Attachments Kind: Visible
|
|
114
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
115
|
+
Attachments Text:
|
|
116
|
+
validate
|
|
117
|
+
Attachment Name: Console Selection
|
|
118
|
+
Attachments Kind: Visible
|
|
119
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
120
|
+
Attachments Text:
|
|
121
|
+
JWT_SECRET=your-secure-jwt-secret-here
|
|
122
|
+
Attachment Name: Console Selection
|
|
123
|
+
Attachments Kind: Visible
|
|
124
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
125
|
+
Attachments Text:
|
|
126
|
+
NODE_ENV
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
kotlin.Unit
|
|
130
|
+
|
|
131
|
+
==== RestoredMessage #10 ====
|
|
132
|
+
Assistant:
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
kotlin.Unit
|
|
136
|
+
|
|
137
|
+
==== RestoredMessage #11 ====
|
|
138
|
+
User:
|
|
139
|
+
I want to offer both choices and build a server-side login page.
|
|
140
|
+
Attachments:
|
|
141
|
+
Attachment Name: Console Selection
|
|
142
|
+
Attachments Kind: Visible
|
|
143
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
144
|
+
Attachments Text:
|
|
145
|
+
process.env.OIDC_REGISTRATION_TOKEN
|
|
146
|
+
Attachment Name: Console Selection
|
|
147
|
+
Attachments Kind: Visible
|
|
148
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
149
|
+
Attachments Text:
|
|
150
|
+
validate
|
|
151
|
+
Attachment Name: Console Selection
|
|
152
|
+
Attachments Kind: Visible
|
|
153
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
154
|
+
Attachments Text:
|
|
155
|
+
JWT_SECRET=your-secure-jwt-secret-here
|
|
156
|
+
Attachment Name: Console Selection
|
|
157
|
+
Attachments Kind: Visible
|
|
158
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
159
|
+
Attachments Text:
|
|
160
|
+
NODE_ENV
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
kotlin.Unit
|
|
164
|
+
|
|
165
|
+
==== RestoredMessage #12 ====
|
|
166
|
+
Assistant:
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
kotlin.Unit
|
|
170
|
+
|
|
171
|
+
==== RestoredMessage #13 ====
|
|
172
|
+
User:
|
|
173
|
+
Do I need to update the express routes, so that they are able to validate users using both approaches?
|
|
174
|
+
Attachments:
|
|
175
|
+
Attachment Name: Console Selection
|
|
176
|
+
Attachments Kind: Visible
|
|
177
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
178
|
+
Attachments Text:
|
|
179
|
+
JWT_SECRET=your-secure-jwt-secret-here
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
kotlin.Unit
|
|
183
|
+
|
|
184
|
+
==== RestoredMessage #14 ====
|
|
185
|
+
Assistant:
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
kotlin.Unit
|
|
189
|
+
|
|
190
|
+
==== RestoredMessage #15 ====
|
|
191
|
+
User:
|
|
192
|
+
I am importing interfaces from the docPouch client I have written. I assume I will have to update some of those, as well, when I update the docPouch client, correct?
|
|
193
|
+
Attachments:
|
|
194
|
+
Attachment Name: Console Selection
|
|
195
|
+
Attachments Kind: Visible
|
|
196
|
+
Attachments Source: Other / RestoredChatAttachment
|
|
197
|
+
Attachments Text:
|
|
198
|
+
JWT_SECRET=your-secure-jwt-secret-here
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
kotlin.Unit
|
|
202
|
+
|
|
203
|
+
==== RestoredMessage #16 ====
|
|
204
|
+
Assistant:
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
kotlin.Unit
|
|
208
|
+
|
|
209
|
+
==== UserMessageImpl #17 ====
|
|
210
|
+
User:
|
|
211
|
+
Yes, I would like to go for Option A and the client should offer different methods for the different auth methods and thus explicitly choose. Please make a detailed plan for yourself, so when I load up my docpouch-client project and give you this instruction, you know exactly what to do.
|
|
212
|
+
|
|
213
|
+
kotlin.Unit
|
|
214
|
+
|
|
215
|
+
==== AgentMessage #18 ====
|
|
216
|
+
Assistant:
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
Tool use list:
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
kotlin.Unit
|
|
223
|
+
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,14 @@ export default class docPouchClient {
|
|
|
34
34
|
* @type {string | null}
|
|
35
35
|
*/
|
|
36
36
|
private authToken;
|
|
37
|
+
private oidcConfig;
|
|
38
|
+
private oidcAccessToken;
|
|
39
|
+
private oidcRefreshToken;
|
|
40
|
+
private oidcIdToken;
|
|
41
|
+
private oidcTokenExpiry;
|
|
42
|
+
private codeVerifier;
|
|
43
|
+
private oidcState;
|
|
44
|
+
private authMethod;
|
|
37
45
|
/**
|
|
38
46
|
* Flag indicating whether a connection attempt is in progress.
|
|
39
47
|
*
|
|
@@ -171,6 +179,81 @@ export default class docPouchClient {
|
|
|
171
179
|
* @returns {void}
|
|
172
180
|
*/
|
|
173
181
|
debugSocketConnection(): void;
|
|
182
|
+
/**
|
|
183
|
+
* Initiates the OIDC authentication flow by redirecting to the authorization endpoint.
|
|
184
|
+
*
|
|
185
|
+
* @param {I_OidcConfig} config - OIDC provider configuration.
|
|
186
|
+
* @returns {Promise<void>}
|
|
187
|
+
*/
|
|
188
|
+
loginWithOidc(config: I_OidcConfig): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Handles the OIDC callback by exchanging the authorization code for tokens.
|
|
191
|
+
*
|
|
192
|
+
* @returns {Promise<boolean>} True if the callback was handled successfully.
|
|
193
|
+
*/
|
|
194
|
+
handleOidcCallback(): Promise<boolean>;
|
|
195
|
+
restoreOidcSession(): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Ensures the OIDC access token is valid, refreshing it if necessary.
|
|
198
|
+
*/
|
|
199
|
+
ensureValidOidcToken(): Promise<string>;
|
|
200
|
+
/**
|
|
201
|
+
* Returns the current authentication method.
|
|
202
|
+
*
|
|
203
|
+
* @returns {'jwt' | 'oidc' | 'none'} The active auth method.
|
|
204
|
+
*/
|
|
205
|
+
getAuthMethod(): 'jwt' | 'oidc' | 'none';
|
|
206
|
+
/**
|
|
207
|
+
* Checks whether the client is currently authenticated.
|
|
208
|
+
*
|
|
209
|
+
* @returns {boolean} True if authenticated.
|
|
210
|
+
*/
|
|
211
|
+
isAuthenticated(): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Returns the current active token, regardless of auth method.
|
|
214
|
+
*
|
|
215
|
+
* @returns {string | null} The active token or null.
|
|
216
|
+
*/
|
|
217
|
+
getToken(): string | null;
|
|
218
|
+
/**
|
|
219
|
+
* Logs out the client, clearing all tokens and disconnecting WebSocket.
|
|
220
|
+
*
|
|
221
|
+
* @returns {Promise<void>}
|
|
222
|
+
*/
|
|
223
|
+
logout(): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Registers a new OIDC client with the server (dynamic client registration).
|
|
226
|
+
*
|
|
227
|
+
* @param {I_OidcClientRegistration} registration - Client metadata for registration.
|
|
228
|
+
* @param {string} [registrationToken] - Initial registration access token. If not provided, the current auth token is used.
|
|
229
|
+
* @returns {Promise<I_OidcClientResponse>} The registered client details.
|
|
230
|
+
*/
|
|
231
|
+
registerOidcClient(registration: I_OidcClientRegistration, registrationToken?: string): Promise<I_OidcClientResponse>;
|
|
232
|
+
/**
|
|
233
|
+
* Retrieves the registration state of an existing OIDC client.
|
|
234
|
+
*
|
|
235
|
+
* @param {string} clientId - The client identifier.
|
|
236
|
+
* @param {string} [registrationToken] - The registration access token. If not provided, the current auth token is used.
|
|
237
|
+
* @returns {Promise<I_OidcClientResponse>} The client details.
|
|
238
|
+
*/
|
|
239
|
+
getOidcClient(clientId: string, registrationToken?: string): Promise<I_OidcClientResponse>;
|
|
240
|
+
/**
|
|
241
|
+
* Updates the registration of an existing OIDC client.
|
|
242
|
+
*
|
|
243
|
+
* @param {string} clientId - The client identifier.
|
|
244
|
+
* @param {I_OidcClientRegistration} registration - Updated client metadata.
|
|
245
|
+
* @param {string} [registrationToken] - The registration access token. If not provided, the current auth token is used.
|
|
246
|
+
* @returns {Promise<I_OidcClientResponse>} The updated client details.
|
|
247
|
+
*/
|
|
248
|
+
updateOidcClient(clientId: string, registration: I_OidcClientRegistration, registrationToken?: string): Promise<I_OidcClientResponse>;
|
|
249
|
+
/**
|
|
250
|
+
* Deletes an OIDC client registration.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} clientId - The client identifier.
|
|
253
|
+
* @param {string} [registrationToken] - The registration access token. If not provided, the current auth token is used.
|
|
254
|
+
* @returns {Promise<void>}
|
|
255
|
+
*/
|
|
256
|
+
deleteOidcClient(clientId: string, registrationToken?: string): Promise<void>;
|
|
174
257
|
/**
|
|
175
258
|
* Sets up permanent socket listeners for the client.
|
|
176
259
|
*
|
|
@@ -195,6 +278,15 @@ export default class docPouchClient {
|
|
|
195
278
|
* @private
|
|
196
279
|
*/
|
|
197
280
|
private request;
|
|
281
|
+
private discoverOidc;
|
|
282
|
+
private setOidcTokens;
|
|
283
|
+
private clearOidcTokens;
|
|
284
|
+
private persistOidcSession;
|
|
285
|
+
private clearPersistedOidcSession;
|
|
286
|
+
private refreshOidcToken;
|
|
287
|
+
private generateCodeVerifier;
|
|
288
|
+
private generateCodeChallenge;
|
|
289
|
+
private generateState;
|
|
198
290
|
}
|
|
199
291
|
export interface I_UserEntry extends I_UserCreation {
|
|
200
292
|
_id: string;
|
|
@@ -229,10 +321,63 @@ export interface I_UserDisplay {
|
|
|
229
321
|
}
|
|
230
322
|
export interface I_LoginResponse {
|
|
231
323
|
_id: string;
|
|
232
|
-
token
|
|
324
|
+
token?: string;
|
|
233
325
|
isAdmin: boolean;
|
|
234
326
|
userName: string;
|
|
327
|
+
expiresIn?: number;
|
|
328
|
+
}
|
|
329
|
+
export interface I_OidcConfig {
|
|
330
|
+
issuer: string;
|
|
331
|
+
clientId: string;
|
|
332
|
+
redirectUri: string;
|
|
333
|
+
scopes?: string[];
|
|
334
|
+
clientSecret?: string;
|
|
335
|
+
}
|
|
336
|
+
export interface I_OidcTokenResponse {
|
|
337
|
+
accessToken: string;
|
|
338
|
+
refreshToken?: string;
|
|
339
|
+
idToken?: string;
|
|
235
340
|
expiresIn: number;
|
|
341
|
+
tokenType: string;
|
|
342
|
+
scope: string;
|
|
343
|
+
}
|
|
344
|
+
export interface I_OidcUserInfo {
|
|
345
|
+
sub: string;
|
|
346
|
+
name?: string;
|
|
347
|
+
email?: string;
|
|
348
|
+
}
|
|
349
|
+
export interface I_OidcClientRegistration {
|
|
350
|
+
client_name: string;
|
|
351
|
+
redirect_uris: string[];
|
|
352
|
+
grant_types?: string[];
|
|
353
|
+
response_types?: string[];
|
|
354
|
+
scope?: string;
|
|
355
|
+
token_endpoint_auth_method?: 'client_secret_basic' | 'client_secret_post' | 'none';
|
|
356
|
+
application_type?: 'web' | 'native';
|
|
357
|
+
logo_uri?: string;
|
|
358
|
+
client_uri?: string;
|
|
359
|
+
policy_uri?: string;
|
|
360
|
+
tos_uri?: string;
|
|
361
|
+
}
|
|
362
|
+
export interface I_OidcClientResponse {
|
|
363
|
+
client_id: string;
|
|
364
|
+
client_secret?: string;
|
|
365
|
+
client_secret_expires_at?: number;
|
|
366
|
+
client_id_issued_at?: number;
|
|
367
|
+
registration_access_token?: string;
|
|
368
|
+
registration_client_uri?: string;
|
|
369
|
+
client_name?: string;
|
|
370
|
+
redirect_uris?: string[];
|
|
371
|
+
grant_types?: string[];
|
|
372
|
+
response_types?: string[];
|
|
373
|
+
scope?: string;
|
|
374
|
+
token_endpoint_auth_method?: string;
|
|
375
|
+
}
|
|
376
|
+
export interface I_AuthState {
|
|
377
|
+
method: 'jwt' | 'oidc' | 'none';
|
|
378
|
+
token: string | null;
|
|
379
|
+
isAdmin: boolean;
|
|
380
|
+
userName: string;
|
|
236
381
|
}
|
|
237
382
|
export interface I_DocumentEntry extends I_DocumentCreationOwned {
|
|
238
383
|
_id: string;
|
|
@@ -281,16 +426,12 @@ export interface I_StructureField {
|
|
|
281
426
|
export interface I_StructureCreation {
|
|
282
427
|
name: string;
|
|
283
428
|
description?: string;
|
|
284
|
-
type: number;
|
|
285
|
-
subType: number;
|
|
286
429
|
fields: I_StructureField[];
|
|
287
430
|
}
|
|
288
431
|
export interface I_StructureUpdate {
|
|
289
432
|
_id?: string;
|
|
290
433
|
name?: string;
|
|
291
434
|
description?: string;
|
|
292
|
-
type?: number;
|
|
293
|
-
subType?: number;
|
|
294
435
|
fields?: I_StructureField[];
|
|
295
436
|
}
|
|
296
437
|
export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" | "newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" | "removedUser" | "removedStructure" | "removedDocument" | "removedType";
|