Skip to content

Adjust config and JWT endpoint for 55 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# FRONTEND
CLIENT_PORT=3100
VITE_METABASE_INSTANCE_URL="http://localhost:3000"
VITE_AUTH_PROVIDER_URI="http://localhost:9090/sso/metabase"

# BACKEND
AUTH_PROVIDER_PORT=9090
Expand Down
3 changes: 0 additions & 3 deletions client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ ENV WATCH=${WATCH}
ARG VITE_METABASE_INSTANCE_URL
ENV VITE_METABASE_INSTANCE_URL=${VITE_METABASE_INSTANCE_URL}

ARG VITE_AUTH_PROVIDER_URI
ENV VITE_AUTH_PROVIDER_URI=${VITE_AUTH_PROVIDER_URI}

WORKDIR /app

COPY ./client ./client
Expand Down
43 changes: 18 additions & 25 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "eslint ."
},
"dependencies": {
"@metabase/embedding-sdk-react": "^0.54.11",
"@metabase/embedding-sdk-react": "^0.55.2-nightly",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
1 change: 0 additions & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
// Configuration
const config = defineMetabaseAuthConfig({
metabaseInstanceUrl: import.meta.env.VITE_METABASE_INSTANCE_URL,
authProviderUri: import.meta.env.VITE_AUTH_PROVIDER_URI,
});

const questionId = 24;
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
MB_JWT_SHARED_SECRET: "${METABASE_JWT_SHARED_SECRET}"
MB_SETUP_TOKEN: "${PREMIUM_EMBEDDING_TOKEN}"
MB_PREMIUM_EMBEDDING_TOKEN: "${PREMIUM_EMBEDDING_TOKEN}"
MB_JWT_IDENTITY_PROVIDER_URI: "http://localhost:${AUTH_PROVIDER_PORT}/sso/metabase"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to merge it right now, we have to disable e2e in this file for the main branch temporarily.
Or wait till sdk@55 is out and update SDK version in package.json.

healthcheck:
test: curl --fail -X GET -I "http://localhost:${MB_PORT}/api/health" || exit 1
interval: 15s
Expand All @@ -30,12 +31,10 @@ services:
dockerfile: ./client/Dockerfile
args:
VITE_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
VITE_AUTH_PROVIDER_URI: "http://localhost:${AUTH_PROVIDER_PORT}/sso/metabase"
WATCH: '${WATCH}'
WATCH: "${WATCH}"
environment:
CLIENT_PORT: "${CLIENT_PORT}"
VITE_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
VITE_AUTH_PROVIDER_URI: "http://localhost:${AUTH_PROVIDER_PORT}/sso/metabase"
ports:
- "${CLIENT_PORT}:${CLIENT_PORT}"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion metabase/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM metabase/metabase-enterprise:v1.54.x
FROM metabase/metabase-enterprise:v1.55.x

COPY ./metabase /app/
COPY ./local-dist /app/local-dist
Expand Down
67 changes: 37 additions & 30 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const express = require('express');
const express = require("express");
const app = express();
const dotenv = require('dotenv').config({ path: '../.env' });
const cors = require('cors');
const dotenv = require("dotenv").config({ path: "../.env" });
const cors = require("cors");
const jwt = require("jsonwebtoken");

app.get('/', (req, res) => {
res.send('Hello from our server!')
})
app.get("/", (req, res) => {
res.send("Hello from our server!");
});

const AUTH_PROVIDER_PORT = process.env.AUTH_PROVIDER_PORT
const METABASE_INSTANCE_URL = process.env.METABASE_INSTANCE_URL
const METABASE_JWT_SHARED_SECRET = process.env.METABASE_JWT_SHARED_SECRET
const AUTH_PROVIDER_PORT = process.env.AUTH_PROVIDER_PORT;
const METABASE_INSTANCE_URL = process.env.METABASE_INSTANCE_URL;
const METABASE_JWT_SHARED_SECRET = process.env.METABASE_JWT_SHARED_SECRET;

app.use(cors({ credentials: true, origin:true })); //https://stackoverflow.com/a/66437447
app.use(cors({ credentials: true, origin: true })); //https://stackoverflow.com/a/66437447

app.get("/sso/metabase", async (req, res) => {

// Usually, you would grab the user from the current session
// Here it is hardcoded for demonstration purposes
// Example:
Expand All @@ -24,15 +23,15 @@ app.get("/sso/metabase", async (req, res) => {
email: "rene@example.com",
firstName: "Rene",
lastName: "Descartes",
group: "Customer"
}
group: "Customer",
};

if (!user) {
console.log("no user");
return res.status(401).json({
status: 'error',
message: 'not authenticated',
})
status: "error",
message: "not authenticated",
});
}

const token = jwt.sign(
Expand All @@ -44,28 +43,36 @@ app.get("/sso/metabase", async (req, res) => {
exp: Math.round(Date.now() / 1000) + 60 * 10, // 10 minutes expiration
},
// This is the JWT signing secret in your Metabase JWT authentication setting
METABASE_JWT_SHARED_SECRET
)
const ssoUrl = `${METABASE_INSTANCE_URL}/auth/sso?token=true&jwt=${token}`
console.log('Hitting MB SSO endpoint', ssoUrl);
METABASE_JWT_SHARED_SECRET,
);

if (req.query.response === "json") {
return res
.status(200)
.set("Content-Type", "application/json")
.send({ jwt: token });
}

const ssoUrl = `${METABASE_INSTANCE_URL}/auth/sso?token=true&jwt=${token}`;
console.log("Hitting MB SSO endpoint", ssoUrl);

try {
const response = await fetch(ssoUrl, { method: 'GET' })
const session = await response.text()
const response = await fetch(ssoUrl, { method: "GET" });
const session = await response.text();

console.log("Received session", session)
return res.status(200).set("Content-Type", "application/json").end(session)
console.log("Received session", session);
return res.status(200).set("Content-Type", "application/json").end(session);
} catch (error) {
if (error instanceof Error) {
res.status(401).json({
status: 'error',
message: 'authentication failed',
status: "error",
message: "authentication failed",
error: error.message,
})
});
}
}
})
});

app.listen(AUTH_PROVIDER_PORT, () => {
console.log(`server listening on port ${AUTH_PROVIDER_PORT}`)
})
console.log(`server listening on port ${AUTH_PROVIDER_PORT}`);
});