Skip to content

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

Default the embed wizard auth mode to SSO when configured, guest otherwise (#74750)

Sébastien8f9478286706
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common-ee.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common-ee.cy.spec.ts
index 08fe84ed190..7934d1687a0 100644
--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common-ee.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common-ee.cy.spec.ts
@@ -2,6 +2,7 @@ import {
ORDERS_COUNT_QUESTION_ID,
ORDERS_QUESTION_ID,
} from "e2e/support/cypress_sample_instance_data";
+import { enableJwtAuth } from "e2e/support/helpers/e2e-jwt-helpers";
import {
getEmbedSidebar,
@@ -115,6 +116,86 @@ describe("scenarios > embedding > sdk iframe embed setup > common", () => {
cy.findByLabelText("Metabase account (SSO)").should("be.enabled");
});
+ describe("default auth mode follows SSO configuration", () => {
+ const openFromCommandPalette = () => {
+ cy.visit("/");
+ H.commandPaletteButton().click();
+ H.commandPaletteInput().should("be.visible").type("new embed");
+ H.commandPalette()
+ .findByRole("option", { name: "New embed" })
+ .should("be.visible")
+ .click();
+ };
+
+ const openFromAdminEmbedding = () => {
+ cy.visit("/admin/embedding");
+ cy.findAllByTestId("sdk-setting-card")
+ .first()
+ .within(() => {
+ cy.findByText("New embed").click();
+ });
+ };
+
+ const openFromAdminGuestEmbeds = () => {
+ cy.visit("/admin/embedding/guest");
+ cy.findAllByTestId("guest-embeds-setting-card")
+ .first()
+ .within(() => {
+ cy.findByText("New embed").click();
+ });
+ };
+
+ const openFromSharingMenu = () => {
+ H.visitQuestion(ORDERS_QUESTION_ID);
+ H.openSharingMenu("Embed");
+ };
+
+ const assertCheckedAuth = (mode: "sso" | "guest") => {
+ const ssoLabel = "Metabase account (SSO)";
+ const guestLabel = "Guest";
+ getEmbedSidebar().within(() => {
+ cy.findByLabelText(mode === "sso" ? ssoLabel : guestLabel).should(
+ "be.checked",
+ );
+ cy.findByLabelText(mode === "sso" ? guestLabel : ssoLabel).should(
+ "not.be.checked",
+ );
+ });
+ };
+
+ it("defaults to SSO from non-guest entry points when JWT SSO is configured (EMB-1783)", () => {
+ enableJwtAuth();
+
+ openFromCommandPalette();
+ assertCheckedAuth("sso");
+
+ openFromAdminEmbedding();
+ assertCheckedAuth("sso");
+
+ openFromSharingMenu();
+ assertCheckedAuth("sso");
+
+ // The Guest embeds admin section is intentionally guest-only and
+ // forces guest mode regardless of SSO configuration.
+ openFromAdminGuestEmbeds();
+ assertCheckedAuth("guest");
+ });
+
+ it("defaults to Guest from all entry points when SSO is not configured", () => {
+ openFromCommandPalette();
+ assertCheckedAuth("guest");
+
+ openFromAdminEmbedding();
+ assertCheckedAuth("guest");
+
+ openFromSharingMenu();
+ assertCheckedAuth("guest");
+
+ openFromAdminGuestEmbeds();
+ assertCheckedAuth("guest");
+ });
+ });
+
it("should not reset experience when changing auth type for Embed JS wizard opened from an entity page", () => {
H.visitQuestion(ORDERS_QUESTION_ID);
diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.ts
index ac8f3f25683..690e1481ab7 100644
--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.ts
+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.ts
@@ -88,6 +88,14 @@ export const useSdkIframeEmbedSettings = ({
const exampleDashboardId = useSetting("example-dashboard-id");
const defaultSettings = useMemo(() => {
+ // Default to SSO when it's available and configured; otherwise default
+ // to guest. Callers that need a specific mode pass `initialState.isGuest`
+ // explicitly.
+ const defaultMode: "sso" | "guest" =
+ isSimpleEmbedFeatureAvailable && isSsoEnabledAndConfigured
+ ? "sso"
+ : "guest";
+
return match(initialState)
.with(
{ resourceType: "dashboard", resourceId: P.nonNullable },
@@ -98,7 +106,7 @@ export const useSdkIframeEmbedSettings = ({
isSimpleEmbedFeatureAvailable,
isGuestEmbedsEnabled,
isSsoEnabledAndConfigured,
- isGuest: !!initialState.isGuest,
+ isGuest: initialState.isGuest ?? defaultMode === "guest",
useExistingUserSession: !!initialState.useExistingUserSession,
}),
)
@@ -111,7 +119,7 @@ export const useSdkIframeEmbedSettings = ({
isSimpleEmbedFeatureAvailable,
isGuestEmbedsEnabled,
isSsoEnabledAndConfigured,
- isGuest: !!initialState.isGuest,
+ isGuest: initialState.isGuest ?? defaultMode === "guest",
useExistingUserSession: !!initialState.useExistingUserSession,
}),
)
@@ -126,7 +134,7 @@ export const useSdkIframeEmbedSettings = ({
isSimpleEmbedFeatureAvailable,
isGuestEmbedsEnabled,
isSsoEnabledAndConfigured,
- isGuest: !!initialState?.isGuest,
+ isGuest: initialState?.isGuest ?? defaultMode === "guest",
useExistingUserSession: !!initialState?.useExistingUserSession,
}),
);
diff --git a/frontend/src/metabase/embedding/hooks/use-sharing-modal.ts b/frontend/src/metabase/embedding/hooks/use-sharing-modal.ts
index a77b5d6086f..ca05f16bc3f 100644
--- a/frontend/src/metabase/embedding/hooks/use-sharing-modal.ts
+++ b/frontend/src/metabase/embedding/hooks/use-sharing-modal.ts
@@ -30,8 +30,6 @@ export const useSharingModal = <
initialState: {
resourceId: resource.id,
resourceType,
- isGuest: true,
- useExistingUserSession: true,
},
});
diff --git a/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx b/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx
index d08e07399fd..d69ce9004f5 100644
--- a/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx
+++ b/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx
@@ -225,12 +225,7 @@ export const useCommandPaletteBasicActions = ({
perform: () =>
openNewModalWithProps({
id: "embed",
- props: {
- initialState: {
- isGuest: true,
- useExistingUserSession: true,
- },
- },
+ props: null,
}),
});
}