@thunderid/browser 1.14.0 → 1.15.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.
package/dist/cjs/index.cjs
CHANGED
|
@@ -695,6 +695,12 @@ var SPAUtils_default = SPAUtils;
|
|
|
695
695
|
|
|
696
696
|
//#endregion
|
|
697
697
|
//#region src/utils/AuthenticationHelper.ts
|
|
698
|
+
/** Methods that change nothing on the server, so sending one twice is harmless. */
|
|
699
|
+
const RETRY_SAFE_HTTP_METHODS = [
|
|
700
|
+
"GET",
|
|
701
|
+
"HEAD",
|
|
702
|
+
"OPTIONS"
|
|
703
|
+
];
|
|
698
704
|
/**
|
|
699
705
|
* Browser-level authentication helper that orchestrates HTTP requests with token attachment,
|
|
700
706
|
* automatic token refresh, and the silent sign-in flow.
|
|
@@ -810,6 +816,21 @@ var AuthenticationHelper = class {
|
|
|
810
816
|
return Promise.reject(error);
|
|
811
817
|
}
|
|
812
818
|
}
|
|
819
|
+
/**
|
|
820
|
+
* Whether a failed request should be sent again after a token refresh: any method on a 401, and
|
|
821
|
+
* only a safe method when there is no response, since the server may have acted on it. A request the
|
|
822
|
+
* caller aborted is never sent again.
|
|
823
|
+
*
|
|
824
|
+
* @param error - The error the request failed with.
|
|
825
|
+
* @param requestConfig - The failed request's configuration.
|
|
826
|
+
* @returns `true` if the request should be sent again after a token refresh.
|
|
827
|
+
*/
|
|
828
|
+
shouldRetryAfterRefresh(error, requestConfig) {
|
|
829
|
+
if (error?.code === "ABORT_ERROR" || error?.name === "AbortError") return false;
|
|
830
|
+
if (error?.response?.status === 401) return true;
|
|
831
|
+
if (error?.response) return false;
|
|
832
|
+
return RETRY_SAFE_HTTP_METHODS.includes((requestConfig?.method ?? "GET").toUpperCase());
|
|
833
|
+
}
|
|
813
834
|
async retryFailedRequests(failedRequest) {
|
|
814
835
|
const { httpClient, requestConfig, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback } = failedRequest;
|
|
815
836
|
await SPAUtils_default.until(() => !this._isTokenRefreshing);
|
|
@@ -825,7 +846,7 @@ var AuthenticationHelper = class {
|
|
|
825
846
|
}
|
|
826
847
|
/**
|
|
827
848
|
* Sends an HTTP request via the provided client, automatically attaching the token,
|
|
828
|
-
* and retries once after a token refresh
|
|
849
|
+
* and retries once after a token refresh when `shouldRetryAfterRefresh` allows it.
|
|
829
850
|
*
|
|
830
851
|
* @param httpClient - The HTTP client to use.
|
|
831
852
|
* @param requestConfig - The request configuration.
|
|
@@ -839,7 +860,7 @@ var AuthenticationHelper = class {
|
|
|
839
860
|
return httpClient.request(requestConfig).then((response) => {
|
|
840
861
|
return Promise.resolve(response);
|
|
841
862
|
}).catch(async (error) => {
|
|
842
|
-
if (error
|
|
863
|
+
if (this.shouldRetryAfterRefresh(error, requestConfig)) {
|
|
843
864
|
if (this._isTokenRefreshing) return this.retryFailedRequests({
|
|
844
865
|
enableRetrievingSignOutURLFromSession,
|
|
845
866
|
httpClient,
|