Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

feat(modular): support relative paths for jwtProviderUri (#69119)

Nicolò Pretto5b8748fda304
diff --git a/enterprise/frontend/src/embedding-sdk-ee/tests/auth-flow/jwt.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-ee/tests/auth-flow/jwt.unit.spec.tsx
index 4eaa81daaa5..3116ca98bc2 100644
--- a/enterprise/frontend/src/embedding-sdk-ee/tests/auth-flow/jwt.unit.spec.tsx
+++ b/enterprise/frontend/src/embedding-sdk-ee/tests/auth-flow/jwt.unit.spec.tsx
@@ -251,4 +251,53 @@ describe("Auth Flow - JWT", () => {
fetchMock.callHistory.calls(`begin:${instanceUrlWithSubpath}/auth/sso`),
).toHaveLength(2);
});
+
+ it("should support relative URLs for jwtProviderUri", async () => {
+ const relativeJwtProviderUri = "/api/sso";
+
+ setupCurrentUserEndpoint(createMockUser());
+ setupPropertiesEndpoints(createMockSettings());
+
+ // Mock the relative JWT provider endpoint (will be resolved to window.location.origin)
+ fetchMock.get(
+ `${window.location.origin}${relativeJwtProviderUri}?response=json`,
+ {
+ status: 200,
+ body: { jwt: MOCK_VALID_JWT_RESPONSE },
+ },
+ );
+
+ // Mock the Metabase SSO validation endpoint
+ fetchMock.get(
+ `${MOCK_INSTANCE_URL}/auth/sso?jwt=${MOCK_VALID_JWT_RESPONSE}`,
+ {
+ status: 200,
+ body: {
+ id: MOCK_SESSION_TOKEN_ID,
+ exp: 1965805007,
+ iat: 1609459200,
+ },
+ },
+ );
+
+ const authConfig = defineMetabaseAuthConfig({
+ metabaseInstanceUrl: MOCK_INSTANCE_URL,
+ jwtProviderUri: relativeJwtProviderUri,
+ });
+
+ renderWithProviders(
+ <ComponentProvider authConfig={authConfig}>
+ <StaticQuestion questionId={1} />
+ </ComponentProvider>,
+ );
+
+ await waitForLoaderToBeRemoved();
+
+ // Verify the relative URL was correctly resolved and called
+ expect(
+ fetchMock.callHistory.calls(
+ `${window.location.origin}${relativeJwtProviderUri}?response=json`,
+ ),
+ ).toHaveLength(1);
+ });
});
diff --git a/enterprise/frontend/src/embedding/auth-common/jwt.ts b/enterprise/frontend/src/embedding/auth-common/jwt.ts
index 54a4828834f..8f17f30bf8e 100644
--- a/enterprise/frontend/src/embedding/auth-common/jwt.ts
+++ b/enterprise/frontend/src/embedding/auth-common/jwt.ts
@@ -90,7 +90,8 @@ const runFetchRequestToken = async (
const refreshUserJwt = async (url: string) => {
let clientBackendResponse;
try {
- const urlWithSource = new URL(url);
+ // Use window.location.origin as base to support relative URLs like "/api/sso"
+ const urlWithSource = new URL(url, window.location.origin);
urlWithSource.searchParams.set("response", "json");
clientBackendResponse = await fetch(urlWithSource.toString(), {
method: "GET",