@axa-fr/react-oidc 6.9.7 → 6.10.0

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.
Files changed (146) hide show
  1. package/README.md +102 -102
  2. package/dist/FetchToken.d.ts.map +1 -1
  3. package/dist/FetchToken.js +2 -2
  4. package/dist/FetchToken.js.map +1 -1
  5. package/dist/OidcProvider.d.ts +7 -6
  6. package/dist/OidcProvider.d.ts.map +1 -1
  7. package/dist/OidcProvider.js +30 -26
  8. package/dist/OidcProvider.js.map +1 -1
  9. package/dist/OidcSecure.d.ts +2 -2
  10. package/dist/OidcSecure.d.ts.map +1 -1
  11. package/dist/OidcSecure.js +2 -4
  12. package/dist/OidcSecure.js.map +1 -1
  13. package/dist/OidcServiceWorker.js +150 -144
  14. package/dist/OidcTrustedDomains.js +9 -10
  15. package/dist/ReactOidc.d.ts +1 -1
  16. package/dist/ReactOidc.d.ts.map +1 -1
  17. package/dist/ReactOidc.js +22 -16
  18. package/dist/ReactOidc.js.map +1 -1
  19. package/dist/User.d.ts.map +1 -1
  20. package/dist/User.js +1 -1
  21. package/dist/User.js.map +1 -1
  22. package/dist/core/default-component/AuthenticateError.component.d.ts +1 -1
  23. package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
  24. package/dist/core/default-component/Authenticating.component.d.ts +1 -1
  25. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  26. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  27. package/dist/core/default-component/Callback.component.js +5 -5
  28. package/dist/core/default-component/Callback.component.js.map +1 -1
  29. package/dist/core/default-component/Loading.component.d.ts +1 -1
  30. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  31. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts +1 -1
  32. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  33. package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
  34. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  35. package/dist/core/default-component/SilentCallback.component.js +1 -0
  36. package/dist/core/default-component/SilentCallback.component.js.map +1 -1
  37. package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
  38. package/dist/core/default-component/SilentLogin.component.js +5 -7
  39. package/dist/core/default-component/SilentLogin.component.js.map +1 -1
  40. package/dist/core/default-component/index.d.ts +2 -2
  41. package/dist/core/default-component/index.d.ts.map +1 -1
  42. package/dist/core/default-component/index.js +5 -5
  43. package/dist/core/default-component/index.js.map +1 -1
  44. package/dist/core/routes/OidcRoutes.d.ts +1 -1
  45. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  46. package/dist/core/routes/OidcRoutes.js +1 -1
  47. package/dist/core/routes/OidcRoutes.js.map +1 -1
  48. package/dist/core/routes/withRouter.d.ts.map +1 -1
  49. package/dist/core/routes/withRouter.js.map +1 -1
  50. package/dist/index.d.ts +7 -6
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +10 -10
  53. package/dist/index.js.map +1 -1
  54. package/dist/vanilla/checkSessionIFrame.d.ts.map +1 -1
  55. package/dist/vanilla/checkSessionIFrame.js +15 -15
  56. package/dist/vanilla/checkSessionIFrame.js.map +1 -1
  57. package/dist/vanilla/initSession.d.ts.map +1 -1
  58. package/dist/vanilla/initSession.js +1 -1
  59. package/dist/vanilla/initSession.js.map +1 -1
  60. package/dist/vanilla/initWorker.d.ts +1 -1
  61. package/dist/vanilla/initWorker.d.ts.map +1 -1
  62. package/dist/vanilla/initWorker.js +22 -20
  63. package/dist/vanilla/initWorker.js.map +1 -1
  64. package/dist/vanilla/memoryStorageBackend.d.ts +5 -4
  65. package/dist/vanilla/memoryStorageBackend.d.ts.map +1 -1
  66. package/dist/vanilla/memoryStorageBackend.js.map +1 -1
  67. package/dist/vanilla/noHashQueryStringUtils.d.ts +3 -3
  68. package/dist/vanilla/noHashQueryStringUtils.d.ts.map +1 -1
  69. package/dist/vanilla/noHashQueryStringUtils.js +4 -4
  70. package/dist/vanilla/noHashQueryStringUtils.js.map +1 -1
  71. package/dist/vanilla/oidc.d.ts +6 -6
  72. package/dist/vanilla/oidc.d.ts.map +1 -1
  73. package/dist/vanilla/oidc.js +215 -216
  74. package/dist/vanilla/oidc.js.map +1 -1
  75. package/dist/vanilla/parseTokens.d.ts +2 -2
  76. package/dist/vanilla/parseTokens.d.ts.map +1 -1
  77. package/dist/vanilla/parseTokens.js +8 -8
  78. package/dist/vanilla/parseTokens.js.map +1 -1
  79. package/dist/vanilla/route-utils.d.ts.map +1 -1
  80. package/dist/vanilla/route-utils.js +10 -7
  81. package/dist/vanilla/route-utils.js.map +1 -1
  82. package/dist/vanilla/timer.d.ts.map +1 -1
  83. package/dist/vanilla/timer.js +8 -8
  84. package/dist/vanilla/timer.js.map +1 -1
  85. package/dist/vanilla/vanillaOidc.d.ts +6 -4
  86. package/dist/vanilla/vanillaOidc.d.ts.map +1 -1
  87. package/dist/vanilla/vanillaOidc.js +4 -5
  88. package/dist/vanilla/vanillaOidc.js.map +1 -1
  89. package/package.json +15 -6
  90. package/src/oidc/FetchToken.tsx +10 -11
  91. package/src/oidc/OidcProvider.tsx +82 -83
  92. package/src/oidc/OidcSecure.tsx +16 -18
  93. package/src/oidc/ReactOidc.tsx +74 -63
  94. package/src/oidc/User.ts +14 -13
  95. package/src/oidc/core/default-component/AuthenticateError.component.tsx +1 -1
  96. package/src/oidc/core/default-component/Authenticating.component.tsx +1 -1
  97. package/src/oidc/core/default-component/Callback.component.tsx +18 -18
  98. package/src/oidc/core/default-component/Loading.component.tsx +1 -1
  99. package/src/oidc/core/default-component/ServiceWorkerNotSupported.component.tsx +1 -1
  100. package/src/oidc/core/default-component/SessionLost.component.tsx +1 -1
  101. package/src/oidc/core/default-component/SilentCallback.component.tsx +7 -6
  102. package/src/oidc/core/default-component/SilentLogin.component.tsx +16 -18
  103. package/src/oidc/core/default-component/index.ts +2 -2
  104. package/src/oidc/core/routes/OidcRoutes.tsx +16 -15
  105. package/src/oidc/core/routes/withRouter.tsx +2 -4
  106. package/src/oidc/index.ts +7 -6
  107. package/src/oidc/vanilla/OidcServiceWorker.js +150 -144
  108. package/src/oidc/vanilla/OidcTrustedDomains.js +9 -10
  109. package/src/oidc/vanilla/checkSessionIFrame.ts +24 -23
  110. package/src/oidc/vanilla/index.ts +2 -1
  111. package/src/oidc/vanilla/initSession.ts +36 -37
  112. package/src/oidc/vanilla/initWorker.ts +82 -83
  113. package/src/oidc/vanilla/memoryStorageBackend.ts +13 -6
  114. package/src/oidc/vanilla/noHashQueryStringUtils.ts +13 -13
  115. package/src/oidc/vanilla/oidc.ts +460 -467
  116. package/src/oidc/vanilla/parseTokens.ts +73 -79
  117. package/src/oidc/vanilla/route-utils.ts +18 -18
  118. package/src/oidc/vanilla/timer.ts +14 -16
  119. package/src/oidc/vanilla/vanillaOidc.ts +35 -19
  120. package/src/override/AuthenticateError.component.tsx +4 -3
  121. package/src/override/Authenticating.component.tsx +4 -3
  122. package/src/override/Callback.component.tsx +4 -3
  123. package/src/override/Loading.component.tsx +4 -6
  124. package/src/override/ServiceWorkerNotSupported.component.tsx +5 -5
  125. package/src/override/SessionLost.component.tsx +8 -7
  126. package/src/override/style.ts +12 -10
  127. package/dist/core/routes/index.d.ts +0 -3
  128. package/dist/core/routes/index.d.ts.map +0 -1
  129. package/dist/core/routes/index.js +0 -9
  130. package/dist/core/routes/index.js.map +0 -1
  131. package/dist/vanilla/index.d.ts +0 -2
  132. package/dist/vanilla/index.d.ts.map +0 -1
  133. package/dist/vanilla/index.js +0 -6
  134. package/dist/vanilla/index.js.map +0 -1
  135. package/src/App.css +0 -38
  136. package/src/App.specold.tsx +0 -46
  137. package/src/App.tsx +0 -103
  138. package/src/FetchUser.tsx +0 -53
  139. package/src/Home.tsx +0 -23
  140. package/src/MultiAuth.tsx +0 -129
  141. package/src/Profile.tsx +0 -81
  142. package/src/configurations.ts +0 -73
  143. package/src/index.css +0 -13
  144. package/src/index.tsx +0 -9
  145. package/src/logo.svg +0 -7
  146. package/src/setupTests.js +0 -5
@@ -1,16 +1,15 @@
1
- import {sleepAsync} from "./initWorker";
2
-
1
+ import { sleepAsync } from './initWorker';
3
2
 
4
3
  const b64DecodeUnicode = (str) =>
5
4
  decodeURIComponent(Array.prototype.map.call(atob(str), (c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join(''));
6
5
  const parseJwt = (token) => JSON.parse(b64DecodeUnicode(token.split('.')[1].replace('-', '+').replace('_', '/')));
7
6
 
8
7
  const extractTokenPayload = (token) => {
9
- try{
8
+ try {
10
9
  if (!token) {
11
10
  return null;
12
11
  }
13
- if(countLetter(token,'.') === 2) {
12
+ if (countLetter(token, '.') === 2) {
14
13
  return parseJwt(token);
15
14
  } else {
16
15
  return null;
@@ -19,132 +18,127 @@ const extractTokenPayload = (token) => {
19
18
  console.warn(e);
20
19
  }
21
20
  return null;
22
- }
21
+ };
23
22
 
24
- const countLetter = (str, find)=> {
23
+ const countLetter = (str, find) => {
25
24
  return (str.split(find)).length - 1;
26
- }
25
+ };
27
26
 
28
27
  export type Tokens = {
29
- refreshToken: string,
30
- idTokenPayload:any,
31
- idToken:string,
32
- accessTokenPayload:any,
33
- accessToken:string,
34
- expiresAt: number,
35
- issuedAt: number
28
+ refreshToken: string;
29
+ idTokenPayload:any;
30
+ idToken:string;
31
+ accessTokenPayload:any;
32
+ accessToken:string;
33
+ expiresAt: number;
34
+ issuedAt: number;
36
35
  };
37
36
 
38
37
  export type TokenRenewModeType = {
39
- access_token_or_id_token_invalid: string,
40
- access_token_invalid:string,
41
- id_token_invalid: string
38
+ access_token_or_id_token_invalid: string;
39
+ access_token_invalid:string;
40
+ id_token_invalid: string;
42
41
  }
43
42
 
44
43
  export const TokenRenewMode = {
45
- access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
46
- access_token_invalid:"access_token_invalid",
47
- id_token_invalid: "id_token_invalid"
48
- }
44
+ access_token_or_id_token_invalid: 'access_token_or_id_token_invalid',
45
+ access_token_invalid: 'access_token_invalid',
46
+ id_token_invalid: 'id_token_invalid',
47
+ };
49
48
 
50
- export const setTokens = (tokens, oldTokens=null, tokenRenewMode: string):Tokens =>{
51
-
52
- if(!tokens){
49
+ export const setTokens = (tokens, oldTokens = null, tokenRenewMode: string):Tokens => {
50
+ if (!tokens) {
53
51
  return null;
54
52
  }
55
53
  let accessTokenPayload;
56
54
 
57
- if(!tokens.issuedAt) {
58
- const currentTimeUnixSecond = new Date().getTime() /1000;
55
+ if (!tokens.issuedAt) {
56
+ const currentTimeUnixSecond = new Date().getTime() / 1000;
59
57
  tokens.issuedAt = currentTimeUnixSecond;
60
58
  }
61
59
 
62
- if(tokens.accessTokenPayload !== undefined) {
60
+ if (tokens.accessTokenPayload !== undefined) {
63
61
  accessTokenPayload = tokens.accessTokenPayload;
64
- }
65
- else {
62
+ } else {
66
63
  accessTokenPayload = extractTokenPayload(tokens.accessToken);
67
64
  }
68
65
  const _idTokenPayload = tokens.idTokenPayload ? tokens.idTokenPayload : extractTokenPayload(tokens.idToken);
69
66
 
70
- const idTokenExpireAt =(_idTokenPayload && _idTokenPayload.exp) ? _idTokenPayload.exp: Number.MAX_VALUE;
71
- const accessTokenExpiresAt = (accessTokenPayload && accessTokenPayload.exp)? accessTokenPayload.exp : tokens.issuedAt + tokens.expiresIn;
67
+ const idTokenExpireAt = (_idTokenPayload && _idTokenPayload.exp) ? _idTokenPayload.exp : Number.MAX_VALUE;
68
+ const accessTokenExpiresAt = (accessTokenPayload && accessTokenPayload.exp) ? accessTokenPayload.exp : tokens.issuedAt + tokens.expiresIn;
69
+
70
+ let expiresAt;
72
71
 
73
- let expiresAt;
74
-
75
72
  if (tokenRenewMode === TokenRenewMode.access_token_invalid) {
76
73
  expiresAt = accessTokenExpiresAt;
77
- } else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
74
+ } else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
78
75
  expiresAt = idTokenExpireAt;
79
76
  } else {
80
77
  expiresAt = idTokenExpireAt < accessTokenExpiresAt ? idTokenExpireAt : accessTokenExpiresAt;
81
- }
82
-
83
- const newTokens = {...tokens, idTokenPayload: _idTokenPayload, accessTokenPayload, expiresAt};
84
- // When refresh_token is not rotated we reuse ald refresh_token
85
- if(oldTokens != null && "refreshToken" in oldTokens && !("refreshToken" in tokens)){
86
- const refreshToken = oldTokens.refreshToken
87
- return {...newTokens, refreshToken};
88
- }
89
-
90
- return newTokens;
91
- }
78
+ }
92
79
 
80
+ const newTokens = { ...tokens, idTokenPayload: _idTokenPayload, accessTokenPayload, expiresAt };
81
+ // When refresh_token is not rotated we reuse ald refresh_token
82
+ if (oldTokens != null && 'refreshToken' in oldTokens && !('refreshToken' in tokens)) {
83
+ const refreshToken = oldTokens.refreshToken;
84
+ return { ...newTokens, refreshToken };
85
+ }
93
86
 
87
+ return newTokens;
88
+ };
94
89
 
95
- export const parseOriginalTokens= (tokens, oldTokens, tokenRenewMode: string ) =>{
96
- if(!tokens){
90
+ export const parseOriginalTokens = (tokens, oldTokens, tokenRenewMode: string) => {
91
+ if (!tokens) {
97
92
  return null;
98
93
  }
99
- if(!tokens.issued_at) {
100
- const currentTimeUnixSecond = new Date().getTime() /1000;
94
+ if (!tokens.issued_at) {
95
+ const currentTimeUnixSecond = new Date().getTime() / 1000;
101
96
  tokens.issued_at = currentTimeUnixSecond;
102
97
  }
103
-
98
+
104
99
  const data = {
105
100
  accessToken: tokens.access_token,
106
101
  expiresIn: tokens.expires_in,
107
102
  idToken: tokens.id_token,
108
103
  scope: tokens.scope,
109
104
  tokenType: tokens.token_type,
110
- issuedAt: tokens.issued_at
105
+ issuedAt: tokens.issued_at,
111
106
  };
112
107
 
113
- if("refresh_token" in tokens) {
108
+ if ('refresh_token' in tokens) {
114
109
  // @ts-ignore
115
- data.refreshToken= tokens.refresh_token;
110
+ data.refreshToken = tokens.refresh_token;
116
111
  }
117
-
118
- if(tokens.accessTokenPayload !== undefined){
112
+
113
+ if (tokens.accessTokenPayload !== undefined) {
119
114
  // @ts-ignore
120
115
  data.accessTokenPayload = tokens.accessTokenPayload;
121
116
  }
122
117
 
123
- if(tokens.idTokenPayload !== undefined){
118
+ if (tokens.idTokenPayload !== undefined) {
124
119
  // @ts-ignore
125
120
  data.idTokenPayload = tokens.idTokenPayload;
126
121
  }
127
122
 
128
123
  return setTokens(data, oldTokens, tokenRenewMode);
129
- }
124
+ };
130
125
 
131
- export const computeTimeLeft = (refreshTimeBeforeTokensExpirationInSecond, expiresAt)=>{
132
- const currentTimeUnixSecond = new Date().getTime() /1000;
126
+ export const computeTimeLeft = (refreshTimeBeforeTokensExpirationInSecond, expiresAt) => {
127
+ const currentTimeUnixSecond = new Date().getTime() / 1000;
133
128
  return Math.round(((expiresAt - refreshTimeBeforeTokensExpirationInSecond) - currentTimeUnixSecond));
134
- }
129
+ };
135
130
 
136
- export const isTokensValid= (tokens) =>{
137
- if(!tokens){
131
+ export const isTokensValid = (tokens) => {
132
+ if (!tokens) {
138
133
  return false;
139
134
  }
140
135
  return computeTimeLeft(0, tokens.expiresAt) > 0;
141
- }
142
-
136
+ };
143
137
 
144
138
  export type ValidToken = {
145
- isTokensValid: Boolean,
146
- tokens: Tokens,
147
- numberWaited: Number
139
+ isTokensValid: boolean;
140
+ tokens: Tokens;
141
+ numberWaited: number;
148
142
  }
149
143
 
150
144
  export interface OidcToken{
@@ -154,38 +148,38 @@ export interface OidcToken{
154
148
  export const getValidTokenAsync = async (oidc: OidcToken, waitMs = 200, numberWait = 50): Promise<ValidToken> => {
155
149
  let numberWaitTemp = numberWait;
156
150
  while (!isTokensValid(oidc.tokens) && numberWaitTemp > 0) {
157
- await sleepAsync(200);
151
+ await sleepAsync(waitMs);
158
152
  numberWaitTemp = numberWaitTemp - 1;
159
153
  }
160
154
  const isValid = isTokensValid(oidc.tokens);
161
155
  return {
162
156
  isTokensValid: isValid,
163
157
  tokens: oidc.tokens,
164
- numberWaited: numberWaitTemp - numberWait
158
+ numberWaited: numberWaitTemp - numberWait,
165
159
  };
166
- }
160
+ };
167
161
 
168
162
  // https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation (excluding rules #1, #4, #5, #7, #8, #12, and #13 which did not apply).
169
163
  // https://github.com/openid/AppAuth-JS/issues/65
170
- export const isTokensOidcValid =(tokens, nonce, oidcServerConfiguration) =>{
171
- if(tokens.idTokenPayload) {
164
+ export const isTokensOidcValid = (tokens, nonce, oidcServerConfiguration) => {
165
+ if (tokens.idTokenPayload) {
172
166
  const idTokenPayload = tokens.idTokenPayload;
173
167
  // 2: The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery) MUST exactly match the value of the iss (issuer) Claim.
174
- if(oidcServerConfiguration.issuer !== idTokenPayload.iss){
168
+ if (oidcServerConfiguration.issuer !== idTokenPayload.iss) {
175
169
  return false;
176
170
  }
177
171
  // 3: The Client MUST validate that the aud (audience) Claim contains its client_id value registered at the Issuer identified by the iss (issuer) Claim as an audience. The aud (audience) Claim MAY contain an array with more than one element. The ID Token MUST be rejected if the ID Token does not list the Client as a valid audience, or if it contains additional audiences not trusted by the Client.
178
-
172
+
179
173
  // 6: If the ID Token is received via direct communication between the Client and the Token Endpoint (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking the token signature. The Client MUST validate the signature of all other ID Tokens according to JWS [JWS] using the algorithm specified in the JWT alg Header Parameter. The Client MUST use the keys provided by the Issuer.
180
-
174
+
181
175
  // 9: The current time MUST be before the time represented by the exp Claim.
182
- const currentTimeUnixSecond = new Date().getTime() /1000;
183
- if(idTokenPayload.exp && idTokenPayload.exp < currentTimeUnixSecond) {
176
+ const currentTimeUnixSecond = new Date().getTime() / 1000;
177
+ if (idTokenPayload.exp && idTokenPayload.exp < currentTimeUnixSecond) {
184
178
  return false;
185
179
  }
186
180
  // 10: The iat Claim can be used to reject tokens that were issued too far away from the current time, limiting the amount of time that nonces need to be stored to prevent attacks. The acceptable range is Client specific.
187
181
  const timeInSevenDays = 60 * 60 * 24 * 7;
188
- if(idTokenPayload.iat && (idTokenPayload.iat + timeInSevenDays) < currentTimeUnixSecond) {
182
+ if (idTokenPayload.iat && (idTokenPayload.iat + timeInSevenDays) < currentTimeUnixSecond) {
189
183
  return false;
190
184
  }
191
185
  // 11: If a nonce value was sent in the Authentication Request, a nonce Claim MUST be present and its value checked to verify that it is the same value as the one that was sent in the Authentication Request. The Client SHOULD check the nonce value for replay attacks. The precise method for detecting replay attacks is Client specific.
@@ -194,4 +188,4 @@ export const isTokensOidcValid =(tokens, nonce, oidcServerConfiguration) =>{
194
188
  }
195
189
  }
196
190
  return true;
197
- }
191
+ };
@@ -1,24 +1,24 @@
1
1
  export const getLocation = (href: string) => {
2
2
  const match = href.match(
3
3
  // eslint-disable-next-line no-useless-escape
4
- /^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/
4
+ /^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/,
5
5
  );
6
-
6
+
7
7
  let search = match[6];
8
8
  let hash = match[7];
9
9
 
10
10
  if (hash) {
11
- const splits = hash.split("?");
12
- if(splits.length ==2){
11
+ const splits = hash.split('?');
12
+ if (splits.length === 2) {
13
13
  hash = splits[0];
14
14
  search = splits[1];
15
15
  }
16
16
  }
17
-
18
- if(search){
17
+
18
+ if (search) {
19
19
  search = search.slice(1);
20
20
  }
21
-
21
+
22
22
  return (
23
23
  match && {
24
24
  href,
@@ -36,14 +36,14 @@ export const getLocation = (href: string) => {
36
36
  export const getPath = (href: string) => {
37
37
  const location = getLocation(href);
38
38
  let { path } = location;
39
-
40
- if(path.endsWith('/')){
39
+
40
+ if (path.endsWith('/')) {
41
41
  path = path.slice(0, -1);
42
42
  }
43
43
  let { hash } = location;
44
-
45
- if(hash === "#_=_"){
46
- hash = "";
44
+
45
+ if (hash === '#_=_') {
46
+ hash = '';
47
47
  }
48
48
 
49
49
  if (hash) {
@@ -53,18 +53,18 @@ export const getPath = (href: string) => {
53
53
  return path;
54
54
  };
55
55
 
56
- export const getParseQueryStringFromLocation=(href: string) => {
56
+ export const getParseQueryStringFromLocation = (href: string) => {
57
57
  const location = getLocation(href);
58
- let { search } = location;
59
-
58
+ const { search } = location;
59
+
60
60
  return parseQueryString(search);
61
- }
61
+ };
62
62
 
63
63
  const parseQueryString = (queryString:string) => {
64
- let params:any = {}, queries, temp, i, l;
64
+ const params:any = {}; let temp; let i; let l;
65
65
 
66
66
  // Split into key/value pairs
67
- queries = queryString.split("&");
67
+ const queries = queryString.split('&');
68
68
 
69
69
  // Convert the array of strings into an object
70
70
  for (i = 0, l = queries.length; i < l; i++) {
@@ -1,4 +1,4 @@
1
- const timer = (function () {
1
+ const timer = (function () {
2
2
  const workerPort = (function () {
3
3
  let worker;
4
4
  let blobURL;
@@ -28,7 +28,7 @@
28
28
  clearInterval: function (port, id) {
29
29
  clearInterval(innerIdsByOuterIds[id]);
30
30
  innerIdsByOuterIds[id] = null;
31
- }
31
+ },
32
32
  };
33
33
 
34
34
  function onMessage(port, event) {
@@ -57,21 +57,20 @@
57
57
  }.toString();
58
58
 
59
59
  try {
60
- const blob = new Blob(['(', workerCode, ')()'], {type: 'application/javascript'});
60
+ const blob = new Blob(['(', workerCode, ')()'], { type: 'application/javascript' });
61
61
  blobURL = URL.createObjectURL(blob);
62
62
  } catch (error) {
63
63
  return null;
64
64
  }
65
- const insideBrowser = (typeof process === 'undefined');
65
+ const isInsideBrowser = (typeof process === 'undefined');
66
66
  try {
67
67
  if (SharedWorker) {
68
68
  worker = new SharedWorker(blobURL);
69
69
  return worker.port;
70
- }
71
- } catch (error)
72
- {
73
- if(insideBrowser) {
74
- console.warn("SharedWorker not available");
70
+ }
71
+ } catch (error) {
72
+ if (isInsideBrowser) {
73
+ console.warn('SharedWorker not available');
75
74
  }
76
75
  }
77
76
  try {
@@ -79,10 +78,9 @@
79
78
  worker = new Worker(blobURL);
80
79
  return worker;
81
80
  }
82
- } catch (error)
83
- {
84
- if(insideBrowser) {
85
- console.warn("Worker not available");
81
+ } catch (error) {
82
+ if (isInsideBrowser) {
83
+ console.warn('Worker not available');
86
84
  }
87
85
  }
88
86
 
@@ -92,13 +90,13 @@
92
90
  if (!workerPort) {
93
91
  // In NextJS with SSR (Server Side Rendering) during rending in Node JS, the window object is undefined,
94
92
  // the global object is used instead as it is the closest approximation of a browsers window object.
95
- const bindContext = (typeof window === 'undefined')? global: window;
93
+ const bindContext = (typeof window === 'undefined') ? global : window;
96
94
 
97
95
  return {
98
96
  setTimeout: setTimeout.bind(bindContext),
99
97
  clearTimeout: clearTimeout.bind(bindContext),
100
98
  setInterval: setInterval.bind(bindContext),
101
- clearInterval: clearInterval.bind(bindContext)
99
+ clearInterval: clearInterval.bind(bindContext),
102
100
  };
103
101
  }
104
102
 
@@ -158,7 +156,7 @@
158
156
  setTimeout: setTimeoutWorker,
159
157
  clearTimeout: clearTimeoutWorker,
160
158
  setInterval: setIntervalWorker,
161
- clearInterval: clearIntervalWorker
159
+ clearInterval: clearIntervalWorker,
162
160
  };
163
161
  }());
164
162
 
@@ -1,58 +1,74 @@
1
- import {LoginCallback, Oidc, OidcConfiguration, StringMap} from "./oidc";
2
- import {getValidTokenAsync, isTokensValid, ValidToken} from "./parseTokens";
3
- import {sleepAsync} from "./initWorker";
4
- import {Tokens} from "./parseTokens";
1
+ import { LoginCallback, Oidc, OidcConfiguration, StringMap } from './oidc';
2
+ import { getValidTokenAsync, Tokens, ValidToken } from './parseTokens';
5
3
 
4
+ export interface EventSubscriber {
5
+ (name: string, data:any);
6
+ }
6
7
 
7
8
  export class VanillaOidc {
8
9
  private _oidc: Oidc;
9
10
  constructor(oidc: Oidc) {
10
11
  this._oidc = oidc;
11
12
  }
12
- subscriveEvents(func:Function):string{
13
- return this._oidc.subscriveEvents(func);
13
+
14
+ subscribeEvents(func:EventSubscriber):string {
15
+ return this._oidc.subscribeEvents(func);
14
16
  }
15
- removeEventSubscription(id:string):void{
17
+
18
+ removeEventSubscription(id:string):void {
16
19
  this._oidc.removeEventSubscription(id);
17
20
  }
18
- publishEvent(eventName:string, data:any) : void{
21
+
22
+ publishEvent(eventName:string, data:any) : void {
19
23
  this._oidc.publishEvent(eventName, data);
20
24
  }
21
- static getOrCreate(configuration:OidcConfiguration, name:string="default"):VanillaOidc {
25
+
26
+ static getOrCreate(configuration:OidcConfiguration, name = 'default'):VanillaOidc {
22
27
  return new VanillaOidc(Oidc.getOrCreate(configuration, name));
23
28
  }
24
- static get(name:string="default"):VanillaOidc {
29
+
30
+ static get(name = 'default'):VanillaOidc {
25
31
  return new VanillaOidc(Oidc.get(name));
26
32
  }
33
+
27
34
  static eventNames = Oidc.eventNames;
28
- tryKeepExistingSessionAsync():Promise<boolean>{
35
+ tryKeepExistingSessionAsync():Promise<boolean> {
29
36
  return this._oidc.tryKeepExistingSessionAsync();
30
37
  }
31
- loginAsync(callbackPath:string=undefined, extras:StringMap=null, isSilentSignin:boolean=false, scope:string=undefined, silentLoginOnly = false):Promise<void> {
38
+
39
+ loginAsync(callbackPath:string = undefined, extras:StringMap = null, isSilentSignin = false, scope:string = undefined, silentLoginOnly = false):Promise<void> {
32
40
  return this._oidc.loginAsync(callbackPath, extras, isSilentSignin, scope, silentLoginOnly);
33
41
  }
42
+
34
43
  logoutAsync(callbackPathOrUrl: string | null | undefined = undefined, extras: StringMap = null):Promise<void> {
35
44
  return this._oidc.logoutAsync(callbackPathOrUrl, extras);
36
45
  }
37
- silentLoginCallbackAsync():Promise<any>{
46
+
47
+ silentLoginCallbackAsync():Promise<any> {
38
48
  return this._oidc.silentLoginCallbackAsync();
39
- };
40
- renewTokensAsync(extras:StringMap=null):Promise<void> {
49
+ }
50
+
51
+ renewTokensAsync(extras:StringMap = null):Promise<void> {
41
52
  return this._oidc.renewTokensAsync(extras);
42
53
  }
43
- loginCallbackAsync():Promise<LoginCallback>{
54
+
55
+ loginCallbackAsync():Promise<LoginCallback> {
44
56
  return this._oidc.loginCallbackWithAutoTokensRenewAsync();
45
57
  }
58
+
46
59
  get tokens():Tokens {
47
60
  return this._oidc.tokens;
48
61
  }
62
+
49
63
  get configuration():OidcConfiguration {
50
64
  return this._oidc.configuration;
51
65
  }
52
- async getValidTokenAsync(waitMs=200, numberWait=50 ): Promise<ValidToken> {
66
+
67
+ async getValidTokenAsync(waitMs = 200, numberWait = 50): Promise<ValidToken> {
53
68
  return getValidTokenAsync(this._oidc, waitMs, numberWait);
54
69
  }
55
- async userInfoAsync():Promise<any>{
70
+
71
+ async userInfoAsync():Promise<any> {
56
72
  return this._oidc.userInfoAsync();
57
73
  }
58
- }
74
+ }
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
- import {ComponentType} from "react";
3
- import {style} from "./style";
2
+ import { ComponentType } from 'react';
4
3
 
5
- const AuthenticatingError: ComponentType<any> = ({configurationName}) => (
4
+ import { style } from './style';
5
+
6
+ const AuthenticatingError: ComponentType<any> = ({ configurationName }) => (
6
7
  <div className="oidc-authenticating" style={style}>
7
8
  <div className="oidc-authenticating__container">
8
9
  <h1 className="oidc-authenticating__title">Error authentication for {configurationName}</h1>
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
- import {PropsWithChildren} from "react";
3
- import {style} from "./style";
2
+ import { PropsWithChildren } from 'react';
4
3
 
5
- const Authenticating : PropsWithChildren<any> = ({configurationName}) => (
4
+ import { style } from './style';
5
+
6
+ const Authenticating : PropsWithChildren<any> = ({ configurationName }) => (
6
7
  <div className="oidc-authenticating" style={style}>
7
8
  <div className="oidc-authenticating__container">
8
9
  <h1 className="oidc-authenticating__title">Authentication in progress for {configurationName}</h1>
@@ -1,7 +1,8 @@
1
- import React, {ComponentType} from 'react';
2
- import {style} from "./style";
1
+ import { ComponentType } from 'react';
3
2
 
4
- export const CallBackSuccess: ComponentType<any> = ({configurationName}) => (<><div className="oidc-callback" style={style}>
3
+ import { style } from './style';
4
+
5
+ export const CallBackSuccess: ComponentType<any> = ({ configurationName }) => (<><div className="oidc-callback" style={style}>
5
6
  <div className="oidc-callback__container">
6
7
  <h1 className="oidc-callback__title">Authentication complete for {configurationName}</h1>
7
8
  <p className="oidc-callback__content">You will be redirected to your application.</p>
@@ -1,13 +1,11 @@
1
- import * as React from 'react';
2
- import {ComponentType } from "react";
3
- import {style} from "./style";
1
+ import { ComponentType } from 'react';
4
2
 
5
- const Loading : ComponentType<any> = ({children, configurationName}) => (
6
- <>
3
+ import { style } from './style';
4
+
5
+ const Loading : ComponentType<any> = ({ configurationName }) => (
7
6
  <span className="oidc-loading" style={style}>
8
7
  Loading for {configurationName}
9
8
  </span>
10
- </>
11
9
  );
12
10
 
13
11
  export default Loading;
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
- import {ComponentType} from "react";
3
- import {style} from "./style";
2
+ import { ComponentType } from 'react';
4
3
 
5
- const ServiceWorkerNotSupported : ComponentType<any> = ({configurationName}) => (
6
- <><div className="oidc-serviceworker" style={style}>
4
+ import { style } from './style';
5
+
6
+ const ServiceWorkerNotSupported : ComponentType<any> = ({ configurationName }) => (
7
+ <div className="oidc-serviceworker" style={style}>
7
8
  <div className="oidc-serviceworker__container">
8
9
  <h1 className="oidc-serviceworker__title">Unable to authenticate on this browser for {configurationName}</h1>
9
10
  <p className="oidc-serviceworker__content">Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser.</p>
10
11
  </div>
11
12
  </div>
12
- </>
13
13
  );
14
14
 
15
15
  export default ServiceWorkerNotSupported;
@@ -1,11 +1,12 @@
1
- import React, {ComponentType} from 'react';
2
- import {style} from "./style"
3
- import {useOidc} from "../oidc";
1
+ import { ComponentType } from 'react';
4
2
 
5
- export const SessionLost: ComponentType<any> = ({configurationName}) => {
6
- const { login} = useOidc(configurationName);
3
+ import { useOidc } from '../oidc';
4
+ import { style } from './style';
7
5
 
8
- return (<>
6
+ export const SessionLost: ComponentType<any> = ({ configurationName }) => {
7
+ const { login } = useOidc(configurationName);
8
+
9
+ return (
9
10
  <div className="oidc-session-lost" style={style}>
10
11
  <div className="oidc-session-lost__container">
11
12
  <h1 className="oidc-session-lost__title">Session timed out for {configurationName}</h1>
@@ -15,7 +16,7 @@ export const SessionLost: ComponentType<any> = ({configurationName}) => {
15
16
  <button type="button" className="btn btn-primary" onClick={() => login(null)}>Login</button>
16
17
  </div>
17
18
  </div>
18
- </>)
19
+ );
19
20
  };
20
21
 
21
22
  export default SessionLost;
@@ -1,10 +1,12 @@
1
- export const style = {
2
- "color": "rgb(53,110,255)",
3
- "backgroundColor": "rgb(255 255 255 / 88%)",
4
- "position": "absolute",
5
- "zIndex": 1000,
6
- "top": "0px",
7
- "bottom": "0px",
8
- "right": "0px",
9
- "left": "0px",
10
- };
1
+ import { CSSProperties } from 'react';
2
+
3
+ export const style: CSSProperties = {
4
+ color: 'rgb(53,110,255)',
5
+ backgroundColor: 'rgb(255 255 255 / 88%)',
6
+ position: 'absolute',
7
+ zIndex: 1000,
8
+ top: '0px',
9
+ bottom: '0px',
10
+ right: '0px',
11
+ left: '0px',
12
+ };
@@ -1,3 +0,0 @@
1
- export { default as OidcRoutes } from './OidcRoutes';
2
- export { ReactOidcHistory } from './withRouter';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/oidc/core/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}