@axa-fr/react-oidc 6.18.3 → 6.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/FetchToken.d.ts +1 -1
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/FetchToken.js +2 -2
- package/dist/FetchToken.js.map +1 -1
- package/dist/service_worker/OidcServiceWorker.js +1 -1
- package/dist/service_worker/OidcServiceWorker.js.map +1 -1
- package/dist/service_worker/types.d.ts +7 -2
- package/dist/service_worker/types.d.ts.map +1 -1
- package/dist/service_worker/utils/domains.d.ts.map +1 -1
- package/dist/service_worker/utils/tokens.d.ts +11 -1
- package/dist/service_worker/utils/tokens.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/service_worker/OidcServiceWorker.ts +27 -5
- package/service_worker/OidcTrustedDomains.js +5 -0
- package/service_worker/dist/OidcServiceWorker.js +1 -1
- package/service_worker/dist/OidcServiceWorker.js.map +1 -1
- package/service_worker/dist/types.d.ts +7 -2
- package/service_worker/dist/types.d.ts.map +1 -1
- package/service_worker/dist/utils/domains.d.ts.map +1 -1
- package/service_worker/dist/utils/tokens.d.ts +11 -1
- package/service_worker/dist/utils/tokens.d.ts.map +1 -1
- package/service_worker/types.ts +10 -2
- package/service_worker/utils/__tests__/domains.spec.ts +1 -0
- package/service_worker/utils/__tests__/testHelper.ts +6 -0
- package/service_worker/utils/__tests__/tokens.spec.ts +26 -2
- package/service_worker/utils/domains.ts +4 -3
- package/service_worker/utils/tokens.ts +92 -84
- package/src/oidc/FetchToken.tsx +2 -2
|
@@ -91,97 +91,104 @@ const isTokensOidcValid = (
|
|
|
91
91
|
return { isValid: true, reason: '' };
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
function _hideTokens(tokens: Tokens, currentDatabaseElement: OidcConfig, configurationName: string) {
|
|
95
|
+
if (!tokens.issued_at) {
|
|
96
|
+
const currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
97
|
+
tokens.issued_at = currentTimeUnixSecond;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const accessTokenPayload = extractTokenPayload(tokens.access_token);
|
|
101
|
+
const secureTokens = {
|
|
102
|
+
...tokens,
|
|
103
|
+
accessTokenPayload,
|
|
104
|
+
};
|
|
105
|
+
if (currentDatabaseElement.hideAccessToken) {
|
|
106
|
+
secureTokens.access_token = TOKEN.ACCESS_TOKEN + '_' + configurationName;
|
|
107
|
+
}
|
|
108
|
+
tokens.accessTokenPayload = accessTokenPayload;
|
|
109
|
+
|
|
110
|
+
let _idTokenPayload = null;
|
|
111
|
+
if (tokens.id_token) {
|
|
112
|
+
_idTokenPayload = extractTokenPayload(tokens.id_token);
|
|
113
|
+
tokens.idTokenPayload = {..._idTokenPayload};
|
|
114
|
+
if (_idTokenPayload.nonce && currentDatabaseElement.nonce != null) {
|
|
115
|
+
const keyNonce =
|
|
116
|
+
TOKEN.NONCE_TOKEN + '_' + currentDatabaseElement.configurationName;
|
|
117
|
+
_idTokenPayload.nonce = keyNonce;
|
|
99
118
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
access_token: TOKEN.ACCESS_TOKEN + '_' + configurationName,
|
|
110
|
-
accessTokenPayload,
|
|
111
|
-
};
|
|
112
|
-
tokens.accessTokenPayload = accessTokenPayload;
|
|
113
|
-
|
|
114
|
-
let _idTokenPayload = null;
|
|
115
|
-
if (tokens.id_token) {
|
|
116
|
-
_idTokenPayload = extractTokenPayload(tokens.id_token);
|
|
117
|
-
tokens.idTokenPayload = { ..._idTokenPayload };
|
|
118
|
-
if (_idTokenPayload.nonce && currentDatabaseElement.nonce != null) {
|
|
119
|
-
const keyNonce =
|
|
120
|
-
TOKEN.NONCE_TOKEN + '_' + currentDatabaseElement.configurationName;
|
|
121
|
-
_idTokenPayload.nonce = keyNonce;
|
|
122
|
-
}
|
|
123
|
-
secureTokens.idTokenPayload = _idTokenPayload;
|
|
124
|
-
}
|
|
125
|
-
if (tokens.refresh_token) {
|
|
126
|
-
secureTokens.refresh_token =
|
|
127
|
-
TOKEN.REFRESH_TOKEN + '_' + configurationName;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const idTokenExpiresAt =
|
|
131
|
-
_idTokenPayload && _idTokenPayload.exp
|
|
119
|
+
secureTokens.idTokenPayload = _idTokenPayload;
|
|
120
|
+
}
|
|
121
|
+
if (tokens.refresh_token) {
|
|
122
|
+
secureTokens.refresh_token =
|
|
123
|
+
TOKEN.REFRESH_TOKEN + '_' + configurationName;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const idTokenExpiresAt =
|
|
127
|
+
_idTokenPayload && _idTokenPayload.exp
|
|
132
128
|
? _idTokenPayload.exp
|
|
133
129
|
: Number.MAX_VALUE;
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
const accessTokenExpiresAt =
|
|
131
|
+
accessTokenPayload && accessTokenPayload.exp
|
|
136
132
|
? accessTokenPayload.exp
|
|
137
133
|
: tokens.issued_at + tokens.expires_in;
|
|
138
134
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
135
|
+
let expiresAt: number;
|
|
136
|
+
const tokenRenewMode = (
|
|
137
|
+
currentDatabaseElement.oidcConfiguration as OidcConfiguration
|
|
138
|
+
).token_renew_mode;
|
|
139
|
+
if (tokenRenewMode === TokenRenewMode.access_token_invalid) {
|
|
140
|
+
expiresAt = accessTokenExpiresAt;
|
|
141
|
+
} else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
|
|
142
|
+
expiresAt = idTokenExpiresAt;
|
|
143
|
+
} else {
|
|
144
|
+
expiresAt =
|
|
145
|
+
idTokenExpiresAt < accessTokenExpiresAt
|
|
150
146
|
? idTokenExpiresAt
|
|
151
147
|
: accessTokenExpiresAt;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
148
|
+
}
|
|
149
|
+
secureTokens.expiresAt = expiresAt;
|
|
150
|
+
|
|
151
|
+
tokens.expiresAt = expiresAt;
|
|
152
|
+
const nonce = currentDatabaseElement.nonce
|
|
153
|
+
? currentDatabaseElement.nonce.nonce
|
|
154
|
+
: null;
|
|
155
|
+
const {isValid, reason} = isTokensOidcValid(
|
|
156
|
+
tokens,
|
|
157
|
+
nonce,
|
|
158
|
+
currentDatabaseElement.oidcServerConfiguration as OidcServerConfiguration
|
|
159
|
+
); //TODO: Type assertion, could be null.
|
|
160
|
+
if (!isValid) {
|
|
161
|
+
throw Error(`Tokens are not OpenID valid, reason: ${reason}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// When refresh_token is not rotated we reuse ald refresh_token
|
|
165
|
+
if (
|
|
166
|
+
currentDatabaseElement.tokens != null &&
|
|
167
|
+
'refresh_token' in currentDatabaseElement.tokens &&
|
|
168
|
+
!('refresh_token' in tokens)
|
|
169
|
+
) {
|
|
170
|
+
const refreshToken = currentDatabaseElement.tokens.refresh_token;
|
|
171
|
+
|
|
172
|
+
currentDatabaseElement.tokens = {
|
|
173
|
+
...tokens,
|
|
174
|
+
refresh_token: refreshToken,
|
|
175
|
+
};
|
|
176
|
+
} else {
|
|
177
|
+
currentDatabaseElement.tokens = tokens;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
currentDatabaseElement.status = 'LOGGED_IN';
|
|
181
|
+
return secureTokens;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function hideTokens(currentDatabaseElement: OidcConfig) {
|
|
185
|
+
const configurationName = currentDatabaseElement.configurationName;
|
|
186
|
+
return (response: Response) => {
|
|
187
|
+
if (response.status !== 200) {
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
return response.json().then<Response>((tokens: Tokens) => {
|
|
191
|
+
const secureTokens = _hideTokens(tokens, currentDatabaseElement, configurationName);
|
|
185
192
|
const body = JSON.stringify(secureTokens);
|
|
186
193
|
return new Response(body, response);
|
|
187
194
|
});
|
|
@@ -194,5 +201,6 @@ export {
|
|
|
194
201
|
isTokensValid,
|
|
195
202
|
extractTokenPayload,
|
|
196
203
|
isTokensOidcValid,
|
|
197
|
-
hideTokens
|
|
204
|
+
hideTokens,
|
|
205
|
+
_hideTokens
|
|
198
206
|
};
|
package/src/oidc/FetchToken.tsx
CHANGED
|
@@ -51,10 +51,10 @@ export const useOidcFetch = (fetch: Fetch = null, configurationName = defaultCon
|
|
|
51
51
|
const getOidc = VanillaOidc.get;
|
|
52
52
|
|
|
53
53
|
const memoizedFetchCallback = useCallback(
|
|
54
|
-
(
|
|
54
|
+
(input: RequestInfo | URL, init?: RequestInit) => {
|
|
55
55
|
const getOidcWithConfigurationName = () => getOidc(configurationName);
|
|
56
56
|
const newFetch = fetchWithToken(previousFetch, getOidcWithConfigurationName);
|
|
57
|
-
return newFetch(
|
|
57
|
+
return newFetch(input, init);
|
|
58
58
|
},
|
|
59
59
|
[previousFetch, configurationName],
|
|
60
60
|
);
|