@axa-fr/react-oidc 6.24.27-alpha928 → 6.25.0-alpha939
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/bin/post-install.js +35 -0
- package/dist/FetchToken.d.ts +2 -3
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/OidcProvider.d.ts +4 -5
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcSecure.d.ts +3 -3
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcServiceWorker.js +559 -0
- package/{service_worker → dist}/OidcTrustedDomains.js +4 -5
- package/dist/ReactOidc.d.ts +4 -4
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/User.d.ts +2 -2
- package/dist/User.d.ts.map +1 -1
- package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
- package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
- package/dist/core/default-component/Callback.component.d.ts.map +1 -1
- package/dist/core/default-component/Loading.component.d.ts.map +1 -1
- package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
- package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
- package/dist/core/default-component/index.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.d.ts +1 -1
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- package/dist/core/routes/index.d.ts +3 -0
- package/dist/core/routes/index.d.ts.map +1 -0
- package/dist/core/routes/withRouter.d.ts +4 -4
- package/dist/core/routes/withRouter.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +964 -21
- package/dist/index.umd.cjs +27 -0
- package/package.json +37 -43
- package/src/{oidc/FetchToken.tsx → FetchToken.tsx} +14 -16
- package/src/{oidc/OidcProvider.tsx → OidcProvider.tsx} +40 -42
- package/src/{oidc/OidcSecure.tsx → OidcSecure.tsx} +1 -3
- package/src/{oidc/ReactOidc.tsx → ReactOidc.tsx} +1 -3
- package/src/{oidc/User.ts → User.ts} +1 -2
- package/src/{oidc/core → core}/default-component/AuthenticateError.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/Authenticating.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/Callback.component.tsx +2 -2
- package/src/{oidc/core → core}/default-component/Loading.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/ServiceWorkerNotSupported.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/SessionLost.component.tsx +1 -1
- package/src/{oidc/core → core}/default-component/SilentCallback.component.tsx +1 -2
- package/src/{oidc/core → core}/default-component/SilentLogin.component.tsx +1 -3
- package/src/{oidc/core → core}/routes/OidcRoutes.spec.tsx +3 -2
- package/src/{oidc/core → core}/routes/OidcRoutes.tsx +6 -6
- package/src/{oidc/core → core}/routes/withRouter.spec.tsx +3 -5
- package/src/{oidc/index.ts → index.ts} +7 -2
- package/bin/copy.cjs +0 -43
- package/dist/FetchToken.js +0 -59
- package/dist/FetchToken.js.map +0 -1
- package/dist/OidcProvider.js +0 -134
- package/dist/OidcProvider.js.map +0 -1
- package/dist/OidcSecure.js +0 -25
- package/dist/OidcSecure.js.map +0 -1
- package/dist/ReactOidc.js +0 -156
- package/dist/ReactOidc.js.map +0 -1
- package/dist/User.js +0 -42
- package/dist/User.js.map +0 -1
- package/dist/core/default-component/AuthenticateError.component.js +0 -6
- package/dist/core/default-component/AuthenticateError.component.js.map +0 -1
- package/dist/core/default-component/Authenticating.component.js +0 -6
- package/dist/core/default-component/Authenticating.component.js.map +0 -1
- package/dist/core/default-component/Callback.component.js +0 -54
- package/dist/core/default-component/Callback.component.js.map +0 -1
- package/dist/core/default-component/Loading.component.js +0 -6
- package/dist/core/default-component/Loading.component.js.map +0 -1
- package/dist/core/default-component/ServiceWorkerNotSupported.component.js +0 -6
- package/dist/core/default-component/ServiceWorkerNotSupported.component.js.map +0 -1
- package/dist/core/default-component/SessionLost.component.js +0 -8
- package/dist/core/default-component/SessionLost.component.js.map +0 -1
- package/dist/core/default-component/SilentCallback.component.js +0 -27
- package/dist/core/default-component/SilentCallback.component.js.map +0 -1
- package/dist/core/default-component/SilentLogin.component.js +0 -29
- package/dist/core/default-component/SilentLogin.component.js.map +0 -1
- package/dist/core/default-component/index.js +0 -20
- package/dist/core/default-component/index.js.map +0 -1
- package/dist/core/routes/OidcRoutes.js +0 -64
- package/dist/core/routes/OidcRoutes.js.map +0 -1
- package/dist/core/routes/withRouter.js +0 -31
- package/dist/core/routes/withRouter.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/service_worker/OidcServiceWorker.d.ts +0 -2
- package/dist/service_worker/OidcServiceWorker.d.ts.map +0 -1
- package/dist/service_worker/OidcServiceWorker.js +0 -2
- package/dist/service_worker/OidcServiceWorker.js.map +0 -1
- package/dist/service_worker/constants.d.ts +0 -18
- package/dist/service_worker/constants.d.ts.map +0 -1
- package/dist/service_worker/types.d.ts +0 -87
- package/dist/service_worker/types.d.ts.map +0 -1
- package/dist/service_worker/utils/codeVerifier.d.ts +0 -2
- package/dist/service_worker/utils/codeVerifier.d.ts.map +0 -1
- package/dist/service_worker/utils/domains.d.ts +0 -7
- package/dist/service_worker/utils/domains.d.ts.map +0 -1
- package/dist/service_worker/utils/index.d.ts +0 -6
- package/dist/service_worker/utils/index.d.ts.map +0 -1
- package/dist/service_worker/utils/serializeHeaders.d.ts +0 -3
- package/dist/service_worker/utils/serializeHeaders.d.ts.map +0 -1
- package/dist/service_worker/utils/sleep.d.ts +0 -3
- package/dist/service_worker/utils/sleep.d.ts.map +0 -1
- package/dist/service_worker/utils/strings.d.ts +0 -8
- package/dist/service_worker/utils/strings.d.ts.map +0 -1
- package/dist/service_worker/utils/tokens.d.ts +0 -22
- package/dist/service_worker/utils/tokens.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vanilla/cache.d.ts +0 -3
- package/dist/vanilla/cache.d.ts.map +0 -1
- package/dist/vanilla/cache.js +0 -30
- package/dist/vanilla/cache.js.map +0 -1
- package/dist/vanilla/checkSession.d.ts +0 -4
- package/dist/vanilla/checkSession.d.ts.map +0 -1
- package/dist/vanilla/checkSession.js +0 -73
- package/dist/vanilla/checkSession.js.map +0 -1
- package/dist/vanilla/checkSessionIFrame.d.ts +0 -17
- package/dist/vanilla/checkSessionIFrame.d.ts.map +0 -1
- package/dist/vanilla/checkSessionIFrame.js +0 -73
- package/dist/vanilla/checkSessionIFrame.js.map +0 -1
- package/dist/vanilla/crypto.d.ts +0 -4
- package/dist/vanilla/crypto.d.ts.map +0 -1
- package/dist/vanilla/crypto.js +0 -85
- package/dist/vanilla/crypto.js.map +0 -1
- package/dist/vanilla/events.d.ts +0 -29
- package/dist/vanilla/events.d.ts.map +0 -1
- package/dist/vanilla/events.js +0 -32
- package/dist/vanilla/events.js.map +0 -1
- package/dist/vanilla/index.d.ts +0 -3
- package/dist/vanilla/index.d.ts.map +0 -1
- package/dist/vanilla/index.js +0 -6
- package/dist/vanilla/index.js.map +0 -1
- package/dist/vanilla/initSession.d.ts +0 -22
- package/dist/vanilla/initSession.d.ts.map +0 -1
- package/dist/vanilla/initSession.js +0 -90
- package/dist/vanilla/initSession.js.map +0 -1
- package/dist/vanilla/initWorker.d.ts +0 -30
- package/dist/vanilla/initWorker.d.ts.map +0 -1
- package/dist/vanilla/initWorker.js +0 -317
- package/dist/vanilla/initWorker.js.map +0 -1
- package/dist/vanilla/login.d.ts +0 -8
- package/dist/vanilla/login.d.ts.map +0 -1
- package/dist/vanilla/login.js +0 -175
- package/dist/vanilla/login.js.map +0 -1
- package/dist/vanilla/logout.d.ts +0 -8
- package/dist/vanilla/logout.d.ts.map +0 -1
- package/dist/vanilla/logout.js +0 -118
- package/dist/vanilla/logout.js.map +0 -1
- package/dist/vanilla/oidc.d.ts +0 -101
- package/dist/vanilla/oidc.d.ts.map +0 -1
- package/dist/vanilla/oidc.js +0 -612
- package/dist/vanilla/oidc.js.map +0 -1
- package/dist/vanilla/parseTokens.d.ts +0 -37
- package/dist/vanilla/parseTokens.d.ts.map +0 -1
- package/dist/vanilla/parseTokens.js +0 -167
- package/dist/vanilla/parseTokens.js.map +0 -1
- package/dist/vanilla/renewTokens.d.ts +0 -4
- package/dist/vanilla/renewTokens.d.ts.map +0 -1
- package/dist/vanilla/renewTokens.js +0 -51
- package/dist/vanilla/renewTokens.js.map +0 -1
- package/dist/vanilla/requests.d.ts +0 -33
- package/dist/vanilla/requests.d.ts.map +0 -1
- package/dist/vanilla/requests.js +0 -174
- package/dist/vanilla/requests.js.map +0 -1
- package/dist/vanilla/route-utils.d.ts +0 -13
- package/dist/vanilla/route-utils.d.ts.map +0 -1
- package/dist/vanilla/route-utils.js +0 -71
- package/dist/vanilla/route-utils.js.map +0 -1
- package/dist/vanilla/silentLogin.d.ts +0 -10
- package/dist/vanilla/silentLogin.d.ts.map +0 -1
- package/dist/vanilla/silentLogin.js +0 -144
- package/dist/vanilla/silentLogin.js.map +0 -1
- package/dist/vanilla/timer.d.ts +0 -8
- package/dist/vanilla/timer.d.ts.map +0 -1
- package/dist/vanilla/timer.js +0 -143
- package/dist/vanilla/timer.js.map +0 -1
- package/dist/vanilla/types.d.ts +0 -38
- package/dist/vanilla/types.d.ts.map +0 -1
- package/dist/vanilla/types.js +0 -3
- package/dist/vanilla/types.js.map +0 -1
- package/dist/vanilla/user.d.ts +0 -2
- package/dist/vanilla/user.d.ts.map +0 -1
- package/dist/vanilla/user.js +0 -48
- package/dist/vanilla/user.js.map +0 -1
- package/dist/vanilla/vanillaOidc.d.ts +0 -85
- package/dist/vanilla/vanillaOidc.d.ts.map +0 -1
- package/dist/vanilla/vanillaOidc.js +0 -71
- package/dist/vanilla/vanillaOidc.js.map +0 -1
- package/service_worker/.eslintrc.cjs +0 -18
- package/service_worker/OidcServiceWorker.ts +0 -424
- package/service_worker/constants.ts +0 -32
- package/service_worker/dist/OidcServiceWorker.d.ts +0 -2
- package/service_worker/dist/OidcServiceWorker.d.ts.map +0 -1
- package/service_worker/dist/OidcServiceWorker.js +0 -2
- package/service_worker/dist/OidcServiceWorker.js.map +0 -1
- package/service_worker/dist/constants.d.ts +0 -18
- package/service_worker/dist/constants.d.ts.map +0 -1
- package/service_worker/dist/types.d.ts +0 -87
- package/service_worker/dist/types.d.ts.map +0 -1
- package/service_worker/dist/utils/codeVerifier.d.ts +0 -2
- package/service_worker/dist/utils/codeVerifier.d.ts.map +0 -1
- package/service_worker/dist/utils/domains.d.ts +0 -7
- package/service_worker/dist/utils/domains.d.ts.map +0 -1
- package/service_worker/dist/utils/index.d.ts +0 -6
- package/service_worker/dist/utils/index.d.ts.map +0 -1
- package/service_worker/dist/utils/serializeHeaders.d.ts +0 -3
- package/service_worker/dist/utils/serializeHeaders.d.ts.map +0 -1
- package/service_worker/dist/utils/sleep.d.ts +0 -3
- package/service_worker/dist/utils/sleep.d.ts.map +0 -1
- package/service_worker/dist/utils/strings.d.ts +0 -8
- package/service_worker/dist/utils/strings.d.ts.map +0 -1
- package/service_worker/dist/utils/tokens.d.ts +0 -22
- package/service_worker/dist/utils/tokens.d.ts.map +0 -1
- package/service_worker/tsconfig.json +0 -26
- package/service_worker/types.ts +0 -103
- package/service_worker/utils/__tests__/codeVerifier.spec.ts +0 -14
- package/service_worker/utils/__tests__/domains.spec.ts +0 -90
- package/service_worker/utils/__tests__/serializeHeaders.spec.ts +0 -11
- package/service_worker/utils/__tests__/strings.spec.ts +0 -9
- package/service_worker/utils/__tests__/testHelper.ts +0 -352
- package/service_worker/utils/__tests__/tokens.spec.ts +0 -92
- package/service_worker/utils/codeVerifier.ts +0 -6
- package/service_worker/utils/domains.ts +0 -105
- package/service_worker/utils/index.ts +0 -5
- package/service_worker/utils/serializeHeaders.ts +0 -12
- package/service_worker/utils/sleep.ts +0 -2
- package/service_worker/utils/strings.ts +0 -9
- package/service_worker/utils/tokens.ts +0 -206
- package/src/oidc/vanilla/cache.ts +0 -27
- package/src/oidc/vanilla/checkSession.ts +0 -60
- package/src/oidc/vanilla/checkSessionIFrame.ts +0 -83
- package/src/oidc/vanilla/crypto.ts +0 -61
- package/src/oidc/vanilla/events.ts +0 -29
- package/src/oidc/vanilla/index.ts +0 -2
- package/src/oidc/vanilla/iniWorker.spec.ts +0 -21
- package/src/oidc/vanilla/initSession.ts +0 -90
- package/src/oidc/vanilla/initWorker.ts +0 -321
- package/src/oidc/vanilla/login.ts +0 -174
- package/src/oidc/vanilla/logout.spec.ts +0 -66
- package/src/oidc/vanilla/logout.spec.tsx +0 -64
- package/src/oidc/vanilla/logout.ts +0 -101
- package/src/oidc/vanilla/oidc.ts +0 -614
- package/src/oidc/vanilla/parseTokens.spec.ts +0 -49
- package/src/oidc/vanilla/parseTokens.ts +0 -194
- package/src/oidc/vanilla/renewTokens.ts +0 -37
- package/src/oidc/vanilla/requests.spec.ts +0 -9
- package/src/oidc/vanilla/requests.ts +0 -169
- package/src/oidc/vanilla/route-utils.spec.ts +0 -23
- package/src/oidc/vanilla/route-utils.ts +0 -79
- package/src/oidc/vanilla/silentLogin.ts +0 -144
- package/src/oidc/vanilla/timer.ts +0 -163
- package/src/oidc/vanilla/types.ts +0 -42
- package/src/oidc/vanilla/user.ts +0 -40
- package/src/oidc/vanilla/vanillaOidc.ts +0 -109
- package/src/override/AuthenticateError.component.tsx +0 -15
- package/src/override/Authenticating.component.tsx +0 -15
- package/src/override/Callback.component.tsx +0 -14
- package/src/override/Loading.component.tsx +0 -11
- package/src/override/ServiceWorkerNotSupported.component.tsx +0 -15
- package/src/override/SessionLost.component.tsx +0 -22
- package/src/override/style.ts +0 -12
- /package/src/{oidc/core → core}/default-component/index.ts +0 -0
- /package/src/{oidc/core → core}/routes/__snapshots__/OidcRoutes.spec.tsx.snap +0 -0
- /package/src/{oidc/core → core}/routes/index.ts +0 -0
- /package/src/{oidc/core → core}/routes/withRouter.tsx +0 -0
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import { vi } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
AccessTokenPayload,
|
|
4
|
-
IdTokenPayload,
|
|
5
|
-
Nonce,
|
|
6
|
-
OidcConfig,
|
|
7
|
-
OidcConfiguration,
|
|
8
|
-
OidcServerConfiguration,
|
|
9
|
-
Status,
|
|
10
|
-
Tokens,
|
|
11
|
-
} from '../../types';
|
|
12
|
-
|
|
13
|
-
const currentTimeUnixSeconds = (): number => {
|
|
14
|
-
return new Date().getTime() / 1000;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const createToken = (expires: number, issued_at: number): Tokens => {
|
|
18
|
-
return {
|
|
19
|
-
expiresAt: expires,
|
|
20
|
-
issued_at: issued_at,
|
|
21
|
-
expires_in: 60,
|
|
22
|
-
id_token: null,
|
|
23
|
-
accessTokenPayload: null,
|
|
24
|
-
access_token: '',
|
|
25
|
-
idTokenPayload: { iss: '', exp: 0, iat: 0, nonce: null },
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
class TokenBuilder {
|
|
30
|
-
private tokens: Tokens = {
|
|
31
|
-
expiresAt: 0,
|
|
32
|
-
issued_at: 0,
|
|
33
|
-
expires_in: 0,
|
|
34
|
-
id_token: null,
|
|
35
|
-
accessTokenPayload: null,
|
|
36
|
-
access_token: '',
|
|
37
|
-
idTokenPayload: { iss: '', exp: 0, iat: 0, nonce: null },
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
constructor() {}
|
|
41
|
-
|
|
42
|
-
public withExpiredToken(): TokenBuilder {
|
|
43
|
-
this.withExpiresIn(currentTimeUnixSeconds() - 10);
|
|
44
|
-
this.withIssuedAt(currentTimeUnixSeconds() - 60);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
public WithNonExpiredToken(): TokenBuilder {
|
|
48
|
-
this.withExpiresAt(currentTimeUnixSeconds() + 60);
|
|
49
|
-
this.withExpiresIn(currentTimeUnixSeconds() + 60);
|
|
50
|
-
this.withIssuedAt(currentTimeUnixSeconds() - 60);
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public withExpiresAt(expiresAt: number): TokenBuilder {
|
|
55
|
-
this.tokens.expiresAt = expiresAt;
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public withIssuedAt(issued_at: number): TokenBuilder {
|
|
60
|
-
this.tokens.issued_at = issued_at;
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public withExpiresIn(expires_in: number): TokenBuilder {
|
|
65
|
-
this.tokens.expires_in = expires_in;
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public withIdToken(id_token: string): TokenBuilder {
|
|
70
|
-
this.tokens.id_token = id_token;
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public withAccessTokenPayload(
|
|
75
|
-
accessTokenPayload: AccessTokenPayload
|
|
76
|
-
): TokenBuilder {
|
|
77
|
-
this.tokens.accessTokenPayload = accessTokenPayload;
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public withAccessToken(access_token: string): TokenBuilder {
|
|
82
|
-
this.tokens.access_token = access_token;
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public withIdTokenPayload(idTokenPayload: IdTokenPayload): TokenBuilder {
|
|
87
|
-
this.tokens.idTokenPayload = idTokenPayload;
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public build(): Tokens {
|
|
92
|
-
return this.tokens;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
class OidcConfigurationBuilder {
|
|
97
|
-
private oidcConfiguration: OidcConfiguration = {
|
|
98
|
-
token_renew_mode: 'offline',
|
|
99
|
-
service_worker_convert_all_requests_to_cors: true,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
constructor() {}
|
|
103
|
-
|
|
104
|
-
public withTokenRenewMode(
|
|
105
|
-
token_renew_mode: string
|
|
106
|
-
): OidcConfigurationBuilder {
|
|
107
|
-
this.oidcConfiguration.token_renew_mode = token_renew_mode;
|
|
108
|
-
return this;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public withServiceWorkerConvertAllRequestsToCors(
|
|
112
|
-
service_worker_convert_all_requests_to_cors: boolean
|
|
113
|
-
): OidcConfigurationBuilder {
|
|
114
|
-
this.oidcConfiguration.service_worker_convert_all_requests_to_cors =
|
|
115
|
-
service_worker_convert_all_requests_to_cors;
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public build(): OidcConfiguration {
|
|
120
|
-
return this.oidcConfiguration;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
class OidcConfigBuilder {
|
|
125
|
-
private oidcConfig: OidcConfig = {
|
|
126
|
-
configurationName: '',
|
|
127
|
-
tokens: null,
|
|
128
|
-
status: 'NOT_CONNECTED',
|
|
129
|
-
state: '',
|
|
130
|
-
codeVerifier: '',
|
|
131
|
-
nonce: null,
|
|
132
|
-
oidcServerConfiguration: null,
|
|
133
|
-
oidcConfiguration: undefined,
|
|
134
|
-
sessionState: null,
|
|
135
|
-
items: undefined,
|
|
136
|
-
hideAccessToken: true,
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
constructor() {}
|
|
140
|
-
|
|
141
|
-
public withTestingDefault(): OidcConfigBuilder {
|
|
142
|
-
this.oidcConfig.configurationName = 'test';
|
|
143
|
-
this.oidcConfig.tokens = new TokenBuilder().WithNonExpiredToken().build();
|
|
144
|
-
this.oidcConfig.status = 'NOT_CONNECTED';
|
|
145
|
-
this.oidcConfig.state = 'state';
|
|
146
|
-
this.oidcConfig.codeVerifier = 'codeVerifier';
|
|
147
|
-
this.oidcConfig.nonce = null;
|
|
148
|
-
this.oidcConfig.oidcConfiguration = new OidcConfigurationBuilder().build();
|
|
149
|
-
this.oidcConfig.oidcServerConfiguration = new OidcServerConfigBuilder()
|
|
150
|
-
.withTestingDefault()
|
|
151
|
-
.build();
|
|
152
|
-
this.oidcConfig.sessionState = null;
|
|
153
|
-
this.oidcConfig.items = undefined;
|
|
154
|
-
this.oidcConfig.hideAccessToken =true;
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public withHideAccessToken(hideAccessToken: boolean): OidcConfigBuilder {
|
|
159
|
-
this.oidcConfig.hideAccessToken = hideAccessToken;
|
|
160
|
-
return this;
|
|
161
|
-
}
|
|
162
|
-
public withConfigurationName(configurationName: string): OidcConfigBuilder {
|
|
163
|
-
this.oidcConfig.configurationName = configurationName;
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public withTokens(tokens: Tokens): OidcConfigBuilder {
|
|
168
|
-
this.oidcConfig.tokens = tokens;
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public withStatus(status: Status): OidcConfigBuilder {
|
|
173
|
-
this.oidcConfig.status = status;
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public withState(state: string): OidcConfigBuilder {
|
|
178
|
-
this.oidcConfig.state = state;
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
public withCodeVerifier(codeVerifier: string): OidcConfigBuilder {
|
|
183
|
-
this.oidcConfig.codeVerifier = codeVerifier;
|
|
184
|
-
return this;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
public withNonce(nonce: Nonce): OidcConfigBuilder {
|
|
188
|
-
this.oidcConfig.nonce = nonce;
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
public withOidcServerConfiguration(
|
|
193
|
-
oidcServerConfiguration: OidcServerConfiguration
|
|
194
|
-
): OidcConfigBuilder {
|
|
195
|
-
this.oidcConfig.oidcServerConfiguration = oidcServerConfiguration;
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
public build() {
|
|
199
|
-
return this.oidcConfig;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
class OidcServerConfigBuilder {
|
|
204
|
-
private oidcServerConfig: OidcServerConfiguration = {
|
|
205
|
-
revocationEndpoint: '',
|
|
206
|
-
issuer: '',
|
|
207
|
-
authorizationEndpoint: '',
|
|
208
|
-
tokenEndpoint: '',
|
|
209
|
-
userInfoEndpoint: '',
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
constructor() {}
|
|
213
|
-
|
|
214
|
-
public withTestingDefault(): OidcServerConfigBuilder {
|
|
215
|
-
this.oidcServerConfig.revocationEndpoint =
|
|
216
|
-
'http://localhost:3000/revocation';
|
|
217
|
-
this.oidcServerConfig.issuer = 'http://localhost:3000';
|
|
218
|
-
this.oidcServerConfig.authorizationEndpoint =
|
|
219
|
-
'http://localhost:3000/authorization';
|
|
220
|
-
this.oidcServerConfig.tokenEndpoint = 'http://localhost:3000/token';
|
|
221
|
-
this.oidcServerConfig.userInfoEndpoint = 'http://localhost:3000/userinfo';
|
|
222
|
-
return this;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
public withRevocationEndpoint(
|
|
226
|
-
revocationEndpoint: string
|
|
227
|
-
): OidcServerConfigBuilder {
|
|
228
|
-
this.oidcServerConfig.revocationEndpoint = revocationEndpoint;
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
public withIssuer(issuer: string): OidcServerConfigBuilder {
|
|
233
|
-
this.oidcServerConfig.issuer = issuer;
|
|
234
|
-
return this;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
public withAuthorizationEndpoint(
|
|
238
|
-
authorizationEndpoint: string
|
|
239
|
-
): OidcServerConfigBuilder {
|
|
240
|
-
this.oidcServerConfig.authorizationEndpoint = authorizationEndpoint;
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
public withTokenEndpoint(tokenEndpoint: string): OidcServerConfigBuilder {
|
|
245
|
-
this.oidcServerConfig.tokenEndpoint = tokenEndpoint;
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
public withUserInfoEndpoint(
|
|
250
|
-
userInfoEndpoint: string
|
|
251
|
-
): OidcServerConfigBuilder {
|
|
252
|
-
this.oidcServerConfig.userInfoEndpoint = userInfoEndpoint;
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
public build(): OidcServerConfiguration {
|
|
257
|
-
return this.oidcServerConfig;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
interface TestingResponse extends Response {
|
|
262
|
-
bodyContent?: any;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
class ResponseBuilder {
|
|
266
|
-
private response: any = {
|
|
267
|
-
status: 200,
|
|
268
|
-
body: '',
|
|
269
|
-
headers: {},
|
|
270
|
-
bodyContent: { issued_at: 343434 },
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
constructor() {}
|
|
274
|
-
|
|
275
|
-
public withStatus(status: number): ResponseBuilder {
|
|
276
|
-
this.response.status = status;
|
|
277
|
-
return this;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
public withBody(body: string): ResponseBuilder {
|
|
281
|
-
this.response.body = body;
|
|
282
|
-
return this;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
public withHeaders(headers: Headers): ResponseBuilder {
|
|
286
|
-
this.response.headers = headers;
|
|
287
|
-
return this;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Custom property for Testing setup
|
|
292
|
-
* @param body
|
|
293
|
-
* @returns
|
|
294
|
-
*/
|
|
295
|
-
public withBodyContent(body: any): ResponseBuilder {
|
|
296
|
-
this.response.bodyContent = body;
|
|
297
|
-
return this;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
public build(): TestingResponse {
|
|
301
|
-
return {
|
|
302
|
-
...{
|
|
303
|
-
status: 200,
|
|
304
|
-
headers: {
|
|
305
|
-
append: vi.fn(),
|
|
306
|
-
delete: vi.fn(),
|
|
307
|
-
forEach: vi.fn(),
|
|
308
|
-
get: vi.fn(),
|
|
309
|
-
has: vi.fn(),
|
|
310
|
-
set: vi.fn(),
|
|
311
|
-
},
|
|
312
|
-
ok: true,
|
|
313
|
-
redirected: false,
|
|
314
|
-
statusText: '',
|
|
315
|
-
type: 'basic',
|
|
316
|
-
url: '',
|
|
317
|
-
clone: function (): Response {
|
|
318
|
-
throw new Error('Function not implemented.');
|
|
319
|
-
},
|
|
320
|
-
body: null,
|
|
321
|
-
bodyUsed: false,
|
|
322
|
-
arrayBuffer: function (): Promise<ArrayBuffer> {
|
|
323
|
-
throw new Error('Function not implemented.');
|
|
324
|
-
},
|
|
325
|
-
blob: function (): Promise<Blob> {
|
|
326
|
-
throw new Error('Function not implemented.');
|
|
327
|
-
},
|
|
328
|
-
formData: function (): Promise<FormData> {
|
|
329
|
-
throw new Error('Function not implemented.');
|
|
330
|
-
},
|
|
331
|
-
json: function (): Promise<any> {
|
|
332
|
-
return new Promise<any>((resolve) => {
|
|
333
|
-
resolve(this.bodyContent);
|
|
334
|
-
});
|
|
335
|
-
},
|
|
336
|
-
text: function (): Promise<string> {
|
|
337
|
-
throw new Error('Function not implemented.');
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
...this.response,
|
|
341
|
-
} as TestingResponse;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
export {
|
|
346
|
-
currentTimeUnixSeconds,
|
|
347
|
-
createToken,
|
|
348
|
-
TokenBuilder,
|
|
349
|
-
OidcServerConfigBuilder,
|
|
350
|
-
OidcConfigBuilder,
|
|
351
|
-
ResponseBuilder,
|
|
352
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { OidcServerConfiguration } from '../../types';
|
|
3
|
-
import {_hideTokens, extractTokenPayload, isTokensOidcValid, isTokensValid} from '..';
|
|
4
|
-
import {OidcConfigBuilder, OidcServerConfigBuilder, TokenBuilder} from './testHelper';
|
|
5
|
-
|
|
6
|
-
describe('tokens', () => {
|
|
7
|
-
let oidcServerConfig: OidcServerConfiguration;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
oidcServerConfig = new OidcServerConfigBuilder()
|
|
11
|
-
.withTestingDefault()
|
|
12
|
-
.build();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('isTokensValid', () => {
|
|
16
|
-
it('can check expired token', () => {
|
|
17
|
-
expect(
|
|
18
|
-
isTokensValid(new TokenBuilder().withExpiredToken().build())
|
|
19
|
-
).toBeFalsy();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('can check non-expired token', () => {
|
|
23
|
-
const token = new TokenBuilder().WithNonExpiredToken().build();
|
|
24
|
-
expect(isTokensValid(token)).toBeTruthy();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('can check null token', () => {
|
|
28
|
-
expect(isTokensValid(null)).toBeFalsy();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('extractTokenPayload', () => {
|
|
33
|
-
it('can extract token payload', () => {
|
|
34
|
-
const result = extractTokenPayload(
|
|
35
|
-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
|
|
36
|
-
);
|
|
37
|
-
expect(result).toEqual({
|
|
38
|
-
sub: '1234567890',
|
|
39
|
-
name: 'John Doe',
|
|
40
|
-
iat: 1516239022,
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
it('returns null if undefined', () => {
|
|
44
|
-
expect(extractTokenPayload(undefined)).toBeNull();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('returns null if invalid token', () => {
|
|
48
|
-
expect(extractTokenPayload('invalid token')).toBeNull();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('isTokensOidcValid', () => {
|
|
53
|
-
it('can validate valid token', () => {
|
|
54
|
-
const token = new TokenBuilder()
|
|
55
|
-
.WithNonExpiredToken()
|
|
56
|
-
.withIdTokenPayload({
|
|
57
|
-
iss: oidcServerConfig.issuer,
|
|
58
|
-
exp: 0,
|
|
59
|
-
iat: 0,
|
|
60
|
-
nonce: null,
|
|
61
|
-
})
|
|
62
|
-
.build();
|
|
63
|
-
const result = isTokensOidcValid(token, null, oidcServerConfig);
|
|
64
|
-
expect(result.isValid).toBeTruthy();
|
|
65
|
-
expect(result.reason).toBe('');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('_hideTokens', () => {
|
|
70
|
-
|
|
71
|
-
it.each([
|
|
72
|
-
{hideAccessToken:true, expectedAccessToken:'ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER_test'},
|
|
73
|
-
{hideAccessToken:false, expectedAccessToken:'test_access_token'},
|
|
74
|
-
])('accesstoken will be hide $hideAccessToken result shoulbe be $expectedAccessToken', ({hideAccessToken, expectedAccessToken}) => {
|
|
75
|
-
const token = new TokenBuilder()
|
|
76
|
-
.withIdTokenPayload({
|
|
77
|
-
iss: oidcServerConfig.issuer,
|
|
78
|
-
exp: 0,
|
|
79
|
-
iat: 0,
|
|
80
|
-
nonce: null,
|
|
81
|
-
})
|
|
82
|
-
.WithNonExpiredToken()
|
|
83
|
-
.withAccessToken('test_access_token')
|
|
84
|
-
.build();
|
|
85
|
-
|
|
86
|
-
const oidcConfiguration = new OidcConfigBuilder().withTestingDefault().withHideAccessToken(hideAccessToken).build()
|
|
87
|
-
const secureTokens = _hideTokens(token, oidcConfiguration, 'test');
|
|
88
|
-
expect(secureTokens.access_token).toBe(expectedAccessToken);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { DomainDetails, TrustedDomains } from './../types';
|
|
2
|
-
import {
|
|
3
|
-
acceptAnyDomainToken,
|
|
4
|
-
openidWellknownUrlEndWith,
|
|
5
|
-
scriptFilename,
|
|
6
|
-
} from '../constants';
|
|
7
|
-
import { Database, Domain, OidcConfig } from '../types';
|
|
8
|
-
|
|
9
|
-
function checkDomain(domains: Domain[], endpoint: string) {
|
|
10
|
-
if (!endpoint) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const domain = domains.find((domain) => {
|
|
15
|
-
let testable: RegExp;
|
|
16
|
-
|
|
17
|
-
if (typeof domain === 'string') {
|
|
18
|
-
testable = new RegExp(`^${domain}`);
|
|
19
|
-
} else {
|
|
20
|
-
testable = domain;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return testable.test?.(endpoint);
|
|
24
|
-
});
|
|
25
|
-
if (!domain) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
'Domain ' +
|
|
28
|
-
endpoint +
|
|
29
|
-
' is not trusted, please add domain in ' +
|
|
30
|
-
scriptFilename
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const getDomains = (trustedDomain: Domain[] | DomainDetails, type: 'oidc' | 'accessToken') => {
|
|
36
|
-
if(Array.isArray(trustedDomain)) {
|
|
37
|
-
return trustedDomain;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return trustedDomain[`${type}Domains`] ?? trustedDomain.domains ?? [];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const getCurrentDatabaseDomain = (
|
|
44
|
-
database: Database,
|
|
45
|
-
url: string,
|
|
46
|
-
trustedDomains: TrustedDomains
|
|
47
|
-
) => {
|
|
48
|
-
if (url.endsWith(openidWellknownUrlEndWith)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
for (const [key, currentDatabase] of Object.entries<OidcConfig>(database)) {
|
|
52
|
-
const oidcServerConfiguration = currentDatabase.oidcServerConfiguration;
|
|
53
|
-
|
|
54
|
-
if (!oidcServerConfiguration) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
oidcServerConfiguration.tokenEndpoint &&
|
|
60
|
-
url === oidcServerConfiguration.tokenEndpoint
|
|
61
|
-
) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (
|
|
65
|
-
oidcServerConfiguration.revocationEndpoint &&
|
|
66
|
-
url === oidcServerConfiguration.revocationEndpoint
|
|
67
|
-
) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const trustedDomain = trustedDomains == null ? [] : trustedDomains[key];
|
|
71
|
-
|
|
72
|
-
const domains = getDomains(trustedDomain, 'accessToken');
|
|
73
|
-
const domainsToSendTokens = oidcServerConfiguration.userInfoEndpoint
|
|
74
|
-
? [oidcServerConfiguration.userInfoEndpoint, ...domains]
|
|
75
|
-
: [...domains];
|
|
76
|
-
|
|
77
|
-
let hasToSendToken = false;
|
|
78
|
-
if (domainsToSendTokens.find((f) => f === acceptAnyDomainToken)) {
|
|
79
|
-
hasToSendToken = true;
|
|
80
|
-
} else {
|
|
81
|
-
for (let i = 0; i < domainsToSendTokens.length; i++) {
|
|
82
|
-
let domain = domainsToSendTokens[i];
|
|
83
|
-
|
|
84
|
-
if (typeof domain === 'string') {
|
|
85
|
-
domain = new RegExp(`^${domain}`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (domain.test?.(url)) {
|
|
89
|
-
hasToSendToken = true;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (hasToSendToken) {
|
|
96
|
-
if (!currentDatabase.tokens) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
return currentDatabase;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export { checkDomain, getCurrentDatabaseDomain };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FetchHeaders } from '../types';
|
|
2
|
-
|
|
3
|
-
function serializeHeaders(headers: Headers) {
|
|
4
|
-
const headersObj: Record<string, string> = {};
|
|
5
|
-
for (const key of (headers as FetchHeaders).keys()) {
|
|
6
|
-
if (headers.has(key)) {
|
|
7
|
-
headersObj[key] = headers.get(key) as string;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return headersObj;
|
|
11
|
-
}
|
|
12
|
-
export {serializeHeaders};
|