docpouch-client 1.0.1 → 1.0.3

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/index.d.ts CHANGED
@@ -179,6 +179,15 @@ export default class docPouchClient {
179
179
  * @returns {void}
180
180
  */
181
181
  debugSocketConnection(): void;
182
+ /**
183
+ * Sets the OIDC configuration to use for the callback and token exchange.
184
+ * Call this before {@link handleOidcCallback} if the client was freshly
185
+ * instantiated after a page reload (the config is otherwise only set
186
+ * internally by {@link loginWithOidc} before the redirect).
187
+ *
188
+ * @param {I_OidcConfig} config - OIDC provider configuration.
189
+ */
190
+ setOidcConfig(config: I_OidcConfig): void;
182
191
  /**
183
192
  * Initiates the OIDC authentication flow by redirecting to the authorization endpoint.
184
193
  *
@@ -330,6 +339,7 @@ export interface I_OidcConfig {
330
339
  issuer: string;
331
340
  clientId: string;
332
341
  redirectUri: string;
342
+ scope?: string;
333
343
  scopes?: string[];
334
344
  clientSecret?: string;
335
345
  }
package/dist/index.js CHANGED
@@ -305,6 +305,17 @@ export default class docPouchClient {
305
305
  }
306
306
  }
307
307
  // OIDC Authentication Methods
308
+ /**
309
+ * Sets the OIDC configuration to use for the callback and token exchange.
310
+ * Call this before {@link handleOidcCallback} if the client was freshly
311
+ * instantiated after a page reload (the config is otherwise only set
312
+ * internally by {@link loginWithOidc} before the redirect).
313
+ *
314
+ * @param {I_OidcConfig} config - OIDC provider configuration.
315
+ */
316
+ setOidcConfig(config) {
317
+ this.oidcConfig = config;
318
+ }
308
319
  /**
309
320
  * Initiates the OIDC authentication flow by redirecting to the authorization endpoint.
310
321
  *
@@ -318,11 +329,19 @@ export default class docPouchClient {
318
329
  this.codeVerifier = this.generateCodeVerifier();
319
330
  this.oidcState = this.generateState();
320
331
  const codeChallenge = await this.generateCodeChallenge(this.codeVerifier);
332
+ if (typeof window !== 'undefined' && window.sessionStorage) {
333
+ sessionStorage.setItem('docpouch_oidc_state', this.oidcState);
334
+ sessionStorage.setItem('docpouch_oidc_code_verifier', this.codeVerifier);
335
+ sessionStorage.setItem('docpouch_oidc_issuer', config.issuer);
336
+ sessionStorage.setItem('docpouch_oidc_client_id', config.clientId);
337
+ sessionStorage.setItem('docpouch_oidc_redirect_uri', config.redirectUri);
338
+ }
339
+ const scope = config.scope || config.scopes?.join(' ') || 'openid profile';
321
340
  const params = new URLSearchParams({
322
341
  response_type: 'code',
323
342
  client_id: config.clientId,
324
343
  redirect_uri: config.redirectUri,
325
- scope: config.scopes?.join(' ') || 'openid profile',
344
+ scope,
326
345
  state: this.oidcState,
327
346
  code_challenge: codeChallenge,
328
347
  code_challenge_method: 'S256'
@@ -343,6 +362,23 @@ export default class docPouchClient {
343
362
  throw new Error(`OAuth error: ${error}`);
344
363
  if (!code || !state)
345
364
  return false;
365
+ if (typeof window !== 'undefined' && window.sessionStorage) {
366
+ this.oidcState = sessionStorage.getItem('docpouch_oidc_state') || this.oidcState;
367
+ this.codeVerifier = sessionStorage.getItem('docpouch_oidc_code_verifier') || this.codeVerifier;
368
+ sessionStorage.removeItem('docpouch_oidc_state');
369
+ sessionStorage.removeItem('docpouch_oidc_code_verifier');
370
+ if (!this.oidcConfig) {
371
+ const issuer = sessionStorage.getItem('docpouch_oidc_issuer');
372
+ const clientId = sessionStorage.getItem('docpouch_oidc_client_id');
373
+ const redirectUri = sessionStorage.getItem('docpouch_oidc_redirect_uri');
374
+ if (issuer && clientId && redirectUri) {
375
+ this.oidcConfig = { issuer, clientId, redirectUri };
376
+ sessionStorage.removeItem('docpouch_oidc_issuer');
377
+ sessionStorage.removeItem('docpouch_oidc_client_id');
378
+ sessionStorage.removeItem('docpouch_oidc_redirect_uri');
379
+ }
380
+ }
381
+ }
346
382
  if (state !== this.oidcState)
347
383
  throw new Error('State mismatch');
348
384
  const discovery = await this.discoverOidc();
package/hff ADDED
@@ -0,0 +1,114 @@
1
+ warning: in the working copy of 'README.md', LF will be replaced by CRLF the next time Git touches it
2
+ warning: in the working copy of 'src/index.ts', LF will be replaced by CRLF the next time Git touches it
3
+ warning: in the working copy of 'tsconfig.json', LF will be replaced by CRLF the next time Git touches it
4
+ diff --git a/package-lock.json b/package-lock.json
5
+ index dacae59..99c15e5 100644
6
+ --- a/package-lock.json
7
+ +++ b/package-lock.json
8
+ @@ -1,12 +1,12 @@
9
+ {
10
+ "name": "docpouch-client",
11
+ - "version": "1.0.0",
12
+ + "version": "1.0.1",
13
+ "lockfileVersion": 3,
14
+ "requires": true,
15
+ "packages": {
16
+ "": {
17
+ "name": "docpouch-client",
18
+ - "version": "1.0.0",
19
+ + "version": "1.0.1",
20
+ "license": "MIT",
21
+ "dependencies": {
22
+ "socket.io-client": "^4.8.3"
23
+ diff --git a/package.json b/package.json
24
+ index 47412b6..61174a1 100644
25
+ --- a/package.json
26
+ +++ b/package.json
27
+ @@ -1,6 +1,6 @@
28
+ {
29
+ "name": "docpouch-client",
30
+ - "version": "1.0.1",
31
+ + "version": "1.0.3",
32
+ "main": "dist/index.js",
33
+ "types": "dist/index.d.ts",
34
+ "exports": {
35
+ diff --git a/src/index.ts b/src/index.ts
36
+ index b9368d4..545dade 100644
37
+ --- a/src/index.ts
38
+ +++ b/src/index.ts
39
+ @@ -358,6 +358,18 @@ export default class docPouchClient {
40
+ 
41
+ // OIDC Authentication Methods
42
+ 
43
+ + /**
44
+ + * Sets the OIDC configuration to use for the callback and token exchange.
45
+ + * Call this before {@link handleOidcCallback} if the client was freshly
46
+ + * instantiated after a page reload (the config is otherwise only set
47
+ + * internally by {@link loginWithOidc} before the redirect).
48
+ + *
49
+ + * @param {I_OidcConfig} config - OIDC provider configuration.
50
+ + */
51
+ + setOidcConfig(config: I_OidcConfig): void {
52
+ + this.oidcConfig = config;
53
+ + }
54
+ +
55
+ /**
56
+ * Initiates the OIDC authentication flow by redirecting to the authorization endpoint.
57
+ *
58
+ @@ -373,11 +385,20 @@ export default class docPouchClient {
59
+ this.oidcState = this.generateState();
60
+ const codeChallenge = await this.generateCodeChallenge(this.codeVerifier!);
61
+ 
62
+ + if (typeof window !== 'undefined' && window.sessionStorage) {
63
+ + sessionStorage.setItem('docpouch_oidc_state', this.oidcState!);
64
+ + sessionStorage.setItem('docpouch_oidc_code_verifier', this.codeVerifier!);
65
+ + sessionStorage.setItem('docpouch_oidc_issuer', config.issuer);
66
+ + sessionStorage.setItem('docpouch_oidc_client_id', config.clientId);
67
+ + sessionStorage.setItem('docpouch_oidc_redirect_uri', config.redirectUri);
68
+ + }
69
+ +
70
+ + const scope = config.scope || config.scopes?.join(' ') || 'openid profile';
71
+ const params = new URLSearchParams({
72
+ response_type: 'code',
73
+ client_id: config.clientId,
74
+ redirect_uri: config.redirectUri,
75
+ - scope: config.scopes?.join(' ') || 'openid profile',
76
+ + scope,
77
+ state: this.oidcState!,
78
+ code_challenge: codeChallenge,
79
+ code_challenge_method: 'S256'
80
+ @@ -399,6 +420,26 @@ export default class docPouchClient {
81
+ 
82
+ if (error) throw new Error(`OAuth error: ${error}`);
83
+ if (!code || !state) return false;
84
+ +
85
+ + if (typeof window !== 'undefined' && window.sessionStorage) {
86
+ + this.oidcState = sessionStorage.getItem('docpouch_oidc_state') || this.oidcState;
87
+ + this.codeVerifier = sessionStorage.getItem('docpouch_oidc_code_verifier') || this.codeVerifier;
88
+ + sessionStorage.removeItem('docpouch_oidc_state');
89
+ + sessionStorage.removeItem('docpouch_oidc_code_verifier');
90
+ +
91
+ + if (!this.oidcConfig) {
92
+ + const issuer = sessionStorage.getItem('docpouch_oidc_issuer');
93
+ + const clientId = sessionStorage.getItem('docpouch_oidc_client_id');
94
+ + const redirectUri = sessionStorage.getItem('docpouch_oidc_redirect_uri');
95
+ + if (issuer && clientId && redirectUri) {
96
+ + this.oidcConfig = { issuer, clientId, redirectUri };
97
+ + sessionStorage.removeItem('docpouch_oidc_issuer');
98
+ + sessionStorage.removeItem('docpouch_oidc_client_id');
99
+ + sessionStorage.removeItem('docpouch_oidc_redirect_uri');
100
+ + }
101
+ + }
102
+ + }
103
+ +
104
+ if (state !== this.oidcState) throw new Error('State mismatch');
105
+ 
106
+ const discovery = await this.discoverOidc();
107
+ @@ -861,6 +902,7 @@ export interface I_OidcConfig {
108
+ issuer: string;
109
+ clientId: string;
110
+ redirectUri: string;
111
+ + scope?: string;
112
+ scopes?: string[];
113
+ clientSecret?: string;
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docpouch-client",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
package/src/index.ts CHANGED
@@ -358,6 +358,18 @@ export default class docPouchClient {
358
358
 
359
359
  // OIDC Authentication Methods
360
360
 
361
+ /**
362
+ * Sets the OIDC configuration to use for the callback and token exchange.
363
+ * Call this before {@link handleOidcCallback} if the client was freshly
364
+ * instantiated after a page reload (the config is otherwise only set
365
+ * internally by {@link loginWithOidc} before the redirect).
366
+ *
367
+ * @param {I_OidcConfig} config - OIDC provider configuration.
368
+ */
369
+ setOidcConfig(config: I_OidcConfig): void {
370
+ this.oidcConfig = config;
371
+ }
372
+
361
373
  /**
362
374
  * Initiates the OIDC authentication flow by redirecting to the authorization endpoint.
363
375
  *
@@ -373,11 +385,20 @@ export default class docPouchClient {
373
385
  this.oidcState = this.generateState();
374
386
  const codeChallenge = await this.generateCodeChallenge(this.codeVerifier!);
375
387
 
388
+ if (typeof window !== 'undefined' && window.sessionStorage) {
389
+ sessionStorage.setItem('docpouch_oidc_state', this.oidcState!);
390
+ sessionStorage.setItem('docpouch_oidc_code_verifier', this.codeVerifier!);
391
+ sessionStorage.setItem('docpouch_oidc_issuer', config.issuer);
392
+ sessionStorage.setItem('docpouch_oidc_client_id', config.clientId);
393
+ sessionStorage.setItem('docpouch_oidc_redirect_uri', config.redirectUri);
394
+ }
395
+
396
+ const scope = config.scope || config.scopes?.join(' ') || 'openid profile';
376
397
  const params = new URLSearchParams({
377
398
  response_type: 'code',
378
399
  client_id: config.clientId,
379
400
  redirect_uri: config.redirectUri,
380
- scope: config.scopes?.join(' ') || 'openid profile',
401
+ scope,
381
402
  state: this.oidcState!,
382
403
  code_challenge: codeChallenge,
383
404
  code_challenge_method: 'S256'
@@ -399,6 +420,26 @@ export default class docPouchClient {
399
420
 
400
421
  if (error) throw new Error(`OAuth error: ${error}`);
401
422
  if (!code || !state) return false;
423
+
424
+ if (typeof window !== 'undefined' && window.sessionStorage) {
425
+ this.oidcState = sessionStorage.getItem('docpouch_oidc_state') || this.oidcState;
426
+ this.codeVerifier = sessionStorage.getItem('docpouch_oidc_code_verifier') || this.codeVerifier;
427
+ sessionStorage.removeItem('docpouch_oidc_state');
428
+ sessionStorage.removeItem('docpouch_oidc_code_verifier');
429
+
430
+ if (!this.oidcConfig) {
431
+ const issuer = sessionStorage.getItem('docpouch_oidc_issuer');
432
+ const clientId = sessionStorage.getItem('docpouch_oidc_client_id');
433
+ const redirectUri = sessionStorage.getItem('docpouch_oidc_redirect_uri');
434
+ if (issuer && clientId && redirectUri) {
435
+ this.oidcConfig = { issuer, clientId, redirectUri };
436
+ sessionStorage.removeItem('docpouch_oidc_issuer');
437
+ sessionStorage.removeItem('docpouch_oidc_client_id');
438
+ sessionStorage.removeItem('docpouch_oidc_redirect_uri');
439
+ }
440
+ }
441
+ }
442
+
402
443
  if (state !== this.oidcState) throw new Error('State mismatch');
403
444
 
404
445
  const discovery = await this.discoverOidc();
@@ -861,6 +902,7 @@ export interface I_OidcConfig {
861
902
  issuer: string;
862
903
  clientId: string;
863
904
  redirectUri: string;
905
+ scope?: string;
864
906
  scopes?: string[];
865
907
  clientSecret?: string;
866
908
  }