From fa86b2e21f40e0f88f044d9f6ea4d36195dcf1b2 Mon Sep 17 00:00:00 2001 From: kavindadewmith Date: Fri, 23 Jan 2026 14:36:31 +0530 Subject: [PATCH 1/4] Refactor HttpClient to support instance-specific instances for multi-auth context --- .../__legacy__/clients/main-thread-client.ts | 2 +- .../http-client/clients/axios-http-client.ts | 75 ++++++++++--------- .../http-client/models/http-client.ts | 2 +- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/packages/browser/src/__legacy__/clients/main-thread-client.ts b/packages/browser/src/__legacy__/clients/main-thread-client.ts index cd0d9908d..79900c12b 100755 --- a/packages/browser/src/__legacy__/clients/main-thread-client.ts +++ b/packages/browser/src/__legacy__/clients/main-thread-client.ts @@ -85,7 +85,7 @@ export const MainThreadClient = async ( let _getSignOutURLFromSessionStorage: boolean = false; - const _httpClient: HttpClientInstance = HttpClient.getInstance(); + const _httpClient: HttpClientInstance = HttpClient.getInstance(instanceID); let _isHttpHandlerEnabled: boolean = true; let _httpErrorCallback: (error: HttpError) => void | Promise; let _httpFinishCallback: () => void; diff --git a/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts b/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts index d6f56f86e..7c675ec6b 100755 --- a/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts +++ b/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts @@ -41,9 +41,9 @@ import {HttpClientInstance, HttpClientInterface, HttpClientStatic} from '../mode */ @staticDecorator>() export class HttpClient implements HttpClientInterface { - private static axiosInstance: HttpClientInstance; - private static clientInstance: HttpClient; - private static isHandlerEnabled: boolean; + private static instances: Map = new Map(); + private static clientInstances: Map = new Map(); + private isHandlerEnabled: boolean = true; private attachToken: (request: HttpRequestConfig) => Promise = () => Promise.resolve(); private requestStartCallback: (request: HttpRequestConfig) => void = () => null; private requestSuccessCallback: (response: HttpResponse) => void = () => null; @@ -66,48 +66,51 @@ export class HttpClient implements HttpClientInterface await this.clientInstance.requestHandler(request as HttpRequestConfig) as InternalAxiosRequestConfig); + axiosInstance.interceptors.request.use(async (request: InternalAxiosRequestConfig) => await clientInstance.requestHandler(request as HttpRequestConfig) as InternalAxiosRequestConfig); // Register response interceptor - this.axiosInstance.interceptors.response.use( - response => this.clientInstance.successHandler(response), - error => this.clientInstance.errorHandler(error), + axiosInstance.interceptors.response.use( + response => clientInstance.successHandler(response), + error => clientInstance.errorHandler(error), ); // Add the missing helper methods from axios - this.axiosInstance.all = axios.all; - this.axiosInstance.spread = axios.spread; + axiosInstance.all = axios.all; + axiosInstance.spread = axios.spread; // Add the init method from the `HttpClient` instance. - this.axiosInstance.init = this.clientInstance.init; + axiosInstance.init = clientInstance.init; // Add the handler enabling & disabling methods to the instance. - this.axiosInstance.enableHandler = this.clientInstance.enableHandler; - this.axiosInstance.disableHandler = this.clientInstance.disableHandler; - this.axiosInstance.disableHandlerWithTimeout = this.clientInstance.disableHandlerWithTimeout; - this.axiosInstance.setHttpRequestStartCallback = this.clientInstance.setHttpRequestStartCallback; - this.axiosInstance.setHttpRequestSuccessCallback = this.clientInstance.setHttpRequestSuccessCallback; - this.axiosInstance.setHttpRequestErrorCallback = this.clientInstance.setHttpRequestErrorCallback; - this.axiosInstance.setHttpRequestFinishCallback = this.clientInstance.setHttpRequestFinishCallback; - return this.axiosInstance; + axiosInstance.enableHandler = clientInstance.enableHandler; + axiosInstance.disableHandler = clientInstance.disableHandler; + axiosInstance.disableHandlerWithTimeout = clientInstance.disableHandlerWithTimeout; + axiosInstance.setHttpRequestStartCallback = clientInstance.setHttpRequestStartCallback; + axiosInstance.setHttpRequestSuccessCallback = clientInstance.setHttpRequestSuccessCallback; + axiosInstance.setHttpRequestErrorCallback = clientInstance.setHttpRequestErrorCallback; + axiosInstance.setHttpRequestFinishCallback = clientInstance.setHttpRequestFinishCallback; + + this.instances.set(instanceId, axiosInstance); + return axiosInstance; } /** @@ -134,7 +137,7 @@ export class HttpClient implements HttpClientInterface Promise, ): Promise { - HttpClient.isHandlerEnabled = isHandlerEnabled; + this.isHandlerEnabled = isHandlerEnabled; this.attachToken = attachToken; } @@ -203,14 +206,14 @@ export class HttpClient implements HttpClientInterface { - HttpClient.isHandlerEnabled = true; + this.isHandlerEnabled = true; }, timeout); } diff --git a/packages/browser/src/__legacy__/http-client/models/http-client.ts b/packages/browser/src/__legacy__/http-client/models/http-client.ts index d6e612fed..9c0783c6b 100644 --- a/packages/browser/src/__legacy__/http-client/models/http-client.ts +++ b/packages/browser/src/__legacy__/http-client/models/http-client.ts @@ -23,7 +23,7 @@ import { HttpError, HttpResponse } from "../../models"; * Http client interface with static functions. */ export interface HttpClientStatic { - getInstance(): S; + getInstance(instanceId?: number): S; } /** From 12fd27504b3b3d433d98218182ebf3ac3a40d1ce Mon Sep 17 00:00:00 2001 From: kavindadewmith Date: Wed, 18 Feb 2026 18:34:10 +0530 Subject: [PATCH 2/4] Refactor HttpClient to initialize isHandlerEnabled value as undefined --- .../src/__legacy__/http-client/clients/axios-http-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts b/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts index 7c675ec6b..fc84a3fb8 100755 --- a/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts +++ b/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts @@ -43,7 +43,7 @@ import {HttpClientInstance, HttpClientInterface, HttpClientStatic} from '../mode export class HttpClient implements HttpClientInterface { private static instances: Map = new Map(); private static clientInstances: Map = new Map(); - private isHandlerEnabled: boolean = true; + private isHandlerEnabled: boolean; private attachToken: (request: HttpRequestConfig) => Promise = () => Promise.resolve(); private requestStartCallback: (request: HttpRequestConfig) => void = () => null; private requestSuccessCallback: (response: HttpResponse) => void = () => null; From d3d6a30114f74c04f91934e9b29c9bf2c1e8f0f5 Mon Sep 17 00:00:00 2001 From: kavindadewmith Date: Thu, 19 Feb 2026 15:41:47 +0530 Subject: [PATCH 3/4] Initialize isHandlerEnabled to true and bind handler methods to correct 'this' context in HttpClient --- .../src/__legacy__/http-client/clients/axios-http-client.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts b/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts index fc84a3fb8..9ce419166 100755 --- a/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts +++ b/packages/browser/src/__legacy__/http-client/clients/axios-http-client.ts @@ -43,7 +43,7 @@ import {HttpClientInstance, HttpClientInterface, HttpClientStatic} from '../mode export class HttpClient implements HttpClientInterface { private static instances: Map = new Map(); private static clientInstances: Map = new Map(); - private isHandlerEnabled: boolean; + private isHandlerEnabled: boolean = true; private attachToken: (request: HttpRequestConfig) => Promise = () => Promise.resolve(); private requestStartCallback: (request: HttpRequestConfig) => void = () => null; private requestSuccessCallback: (response: HttpResponse) => void = () => null; @@ -59,6 +59,9 @@ export class HttpClient implements HttpClientInterface Date: Thu, 19 Feb 2026 15:58:41 +0530 Subject: [PATCH 4/4] =?UTF-8?q?Add=20changeset=20=F0=9F=A6=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/light-queens-rest.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/light-queens-rest.md diff --git a/.changeset/light-queens-rest.md b/.changeset/light-queens-rest.md new file mode 100644 index 000000000..6cdfdf1e4 --- /dev/null +++ b/.changeset/light-queens-rest.md @@ -0,0 +1,5 @@ +--- +'@asgardeo/browser': minor +--- + +Fix failure of calling authenticated APIs from secondary AsgardeoProvider Instances in Multi Provider scenarios