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 +10 -0
- package/dist/index.js +37 -1
- package/hff +114 -0
- package/package.json +1 -1
- package/src/index.ts +43 -1
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
|
|
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
|
+
[1mdiff --git a/package-lock.json b/package-lock.json[m
|
|
5
|
+
[1mindex dacae59..99c15e5 100644[m
|
|
6
|
+
[1m--- a/package-lock.json[m
|
|
7
|
+
[1m+++ b/package-lock.json[m
|
|
8
|
+
[36m@@ -1,12 +1,12 @@[m
|
|
9
|
+
{[m
|
|
10
|
+
"name": "docpouch-client",[m
|
|
11
|
+
[31m- "version": "1.0.0",[m
|
|
12
|
+
[32m+[m[32m "version": "1.0.1",[m
|
|
13
|
+
"lockfileVersion": 3,[m
|
|
14
|
+
"requires": true,[m
|
|
15
|
+
"packages": {[m
|
|
16
|
+
"": {[m
|
|
17
|
+
"name": "docpouch-client",[m
|
|
18
|
+
[31m- "version": "1.0.0",[m
|
|
19
|
+
[32m+[m[32m "version": "1.0.1",[m
|
|
20
|
+
"license": "MIT",[m
|
|
21
|
+
"dependencies": {[m
|
|
22
|
+
"socket.io-client": "^4.8.3"[m
|
|
23
|
+
[1mdiff --git a/package.json b/package.json[m
|
|
24
|
+
[1mindex 47412b6..61174a1 100644[m
|
|
25
|
+
[1m--- a/package.json[m
|
|
26
|
+
[1m+++ b/package.json[m
|
|
27
|
+
[36m@@ -1,6 +1,6 @@[m
|
|
28
|
+
{[m
|
|
29
|
+
"name": "docpouch-client",[m
|
|
30
|
+
[31m- "version": "1.0.1",[m
|
|
31
|
+
[32m+[m[32m "version": "1.0.3",[m
|
|
32
|
+
"main": "dist/index.js",[m
|
|
33
|
+
"types": "dist/index.d.ts",[m
|
|
34
|
+
"exports": {[m
|
|
35
|
+
[1mdiff --git a/src/index.ts b/src/index.ts[m
|
|
36
|
+
[1mindex b9368d4..545dade 100644[m
|
|
37
|
+
[1m--- a/src/index.ts[m
|
|
38
|
+
[1m+++ b/src/index.ts[m
|
|
39
|
+
[36m@@ -358,6 +358,18 @@[m [mexport default class docPouchClient {[m
|
|
40
|
+
[m
|
|
41
|
+
// OIDC Authentication Methods[m
|
|
42
|
+
[m
|
|
43
|
+
[32m+[m[32m /**[m
|
|
44
|
+
[32m+[m[32m * Sets the OIDC configuration to use for the callback and token exchange.[m
|
|
45
|
+
[32m+[m[32m * Call this before {@link handleOidcCallback} if the client was freshly[m
|
|
46
|
+
[32m+[m[32m * instantiated after a page reload (the config is otherwise only set[m
|
|
47
|
+
[32m+[m[32m * internally by {@link loginWithOidc} before the redirect).[m
|
|
48
|
+
[32m+[m[32m *[m
|
|
49
|
+
[32m+[m[32m * @param {I_OidcConfig} config - OIDC provider configuration.[m
|
|
50
|
+
[32m+[m[32m */[m
|
|
51
|
+
[32m+[m[32m setOidcConfig(config: I_OidcConfig): void {[m
|
|
52
|
+
[32m+[m[32m this.oidcConfig = config;[m
|
|
53
|
+
[32m+[m[32m }[m
|
|
54
|
+
[32m+[m
|
|
55
|
+
/**[m
|
|
56
|
+
* Initiates the OIDC authentication flow by redirecting to the authorization endpoint.[m
|
|
57
|
+
*[m
|
|
58
|
+
[36m@@ -373,11 +385,20 @@[m [mexport default class docPouchClient {[m
|
|
59
|
+
this.oidcState = this.generateState();[m
|
|
60
|
+
const codeChallenge = await this.generateCodeChallenge(this.codeVerifier!);[m
|
|
61
|
+
[m
|
|
62
|
+
[32m+[m[32m if (typeof window !== 'undefined' && window.sessionStorage) {[m
|
|
63
|
+
[32m+[m[32m sessionStorage.setItem('docpouch_oidc_state', this.oidcState!);[m
|
|
64
|
+
[32m+[m[32m sessionStorage.setItem('docpouch_oidc_code_verifier', this.codeVerifier!);[m
|
|
65
|
+
[32m+[m[32m sessionStorage.setItem('docpouch_oidc_issuer', config.issuer);[m
|
|
66
|
+
[32m+[m[32m sessionStorage.setItem('docpouch_oidc_client_id', config.clientId);[m
|
|
67
|
+
[32m+[m[32m sessionStorage.setItem('docpouch_oidc_redirect_uri', config.redirectUri);[m
|
|
68
|
+
[32m+[m[32m }[m
|
|
69
|
+
[32m+[m
|
|
70
|
+
[32m+[m[32m const scope = config.scope || config.scopes?.join(' ') || 'openid profile';[m
|
|
71
|
+
const params = new URLSearchParams({[m
|
|
72
|
+
response_type: 'code',[m
|
|
73
|
+
client_id: config.clientId,[m
|
|
74
|
+
redirect_uri: config.redirectUri,[m
|
|
75
|
+
[31m- scope: config.scopes?.join(' ') || 'openid profile',[m
|
|
76
|
+
[32m+[m[32m scope,[m
|
|
77
|
+
state: this.oidcState!,[m
|
|
78
|
+
code_challenge: codeChallenge,[m
|
|
79
|
+
code_challenge_method: 'S256'[m
|
|
80
|
+
[36m@@ -399,6 +420,26 @@[m [mexport default class docPouchClient {[m
|
|
81
|
+
[m
|
|
82
|
+
if (error) throw new Error(`OAuth error: ${error}`);[m
|
|
83
|
+
if (!code || !state) return false;[m
|
|
84
|
+
[32m+[m
|
|
85
|
+
[32m+[m[32m if (typeof window !== 'undefined' && window.sessionStorage) {[m
|
|
86
|
+
[32m+[m[32m this.oidcState = sessionStorage.getItem('docpouch_oidc_state') || this.oidcState;[m
|
|
87
|
+
[32m+[m[32m this.codeVerifier = sessionStorage.getItem('docpouch_oidc_code_verifier') || this.codeVerifier;[m
|
|
88
|
+
[32m+[m[32m sessionStorage.removeItem('docpouch_oidc_state');[m
|
|
89
|
+
[32m+[m[32m sessionStorage.removeItem('docpouch_oidc_code_verifier');[m
|
|
90
|
+
[32m+[m
|
|
91
|
+
[32m+[m[32m if (!this.oidcConfig) {[m
|
|
92
|
+
[32m+[m[32m const issuer = sessionStorage.getItem('docpouch_oidc_issuer');[m
|
|
93
|
+
[32m+[m[32m const clientId = sessionStorage.getItem('docpouch_oidc_client_id');[m
|
|
94
|
+
[32m+[m[32m const redirectUri = sessionStorage.getItem('docpouch_oidc_redirect_uri');[m
|
|
95
|
+
[32m+[m[32m if (issuer && clientId && redirectUri) {[m
|
|
96
|
+
[32m+[m[32m this.oidcConfig = { issuer, clientId, redirectUri };[m
|
|
97
|
+
[32m+[m[32m sessionStorage.removeItem('docpouch_oidc_issuer');[m
|
|
98
|
+
[32m+[m[32m sessionStorage.removeItem('docpouch_oidc_client_id');[m
|
|
99
|
+
[32m+[m[32m sessionStorage.removeItem('docpouch_oidc_redirect_uri');[m
|
|
100
|
+
[32m+[m[32m }[m
|
|
101
|
+
[32m+[m[32m }[m
|
|
102
|
+
[32m+[m[32m }[m
|
|
103
|
+
[32m+[m
|
|
104
|
+
if (state !== this.oidcState) throw new Error('State mismatch');[m
|
|
105
|
+
[m
|
|
106
|
+
const discovery = await this.discoverOidc();[m
|
|
107
|
+
[36m@@ -861,6 +902,7 @@[m [mexport interface I_OidcConfig {[m
|
|
108
|
+
issuer: string;[m
|
|
109
|
+
clientId: string;[m
|
|
110
|
+
redirectUri: string;[m
|
|
111
|
+
[32m+[m[32m scope?: string;[m
|
|
112
|
+
scopes?: string[];[m
|
|
113
|
+
clientSecret?: string;[m
|
|
114
|
+
}[m
|
package/package.json
CHANGED
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
|
|
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
|
}
|