Skip to content

Commit 41bf14d

Browse files
Adjust config and JWT endpoint for 55 (#30)
Co-authored-by: sanex3339 <sanex3339@yandex.ru>
1 parent b6b40e9 commit 41bf14d

File tree

8 files changed

+59
-65
lines changed

8 files changed

+59
-65
lines changed

.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# FRONTEND
22
CLIENT_PORT=3100
33
VITE_METABASE_INSTANCE_URL="http://localhost:3000"
4-
VITE_AUTH_PROVIDER_URI="http://localhost:9090/sso/metabase"
54

65
# BACKEND
76
AUTH_PROVIDER_PORT=9090

client/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ ENV WATCH=${WATCH}
66
ARG VITE_METABASE_INSTANCE_URL
77
ENV VITE_METABASE_INSTANCE_URL=${VITE_METABASE_INSTANCE_URL}
88

9-
ARG VITE_AUTH_PROVIDER_URI
10-
ENV VITE_AUTH_PROVIDER_URI=${VITE_AUTH_PROVIDER_URI}
11-
129
WORKDIR /app
1310

1411
COPY ./client ./client

client/package-lock.json

Lines changed: 18 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint ."
1212
},
1313
"dependencies": {
14-
"@metabase/embedding-sdk-react": "^0.54.11",
14+
"@metabase/embedding-sdk-react": "^0.55.2-nightly",
1515
"react": "^18.3.1",
1616
"react-dom": "^18.3.1"
1717
},

client/src/App.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
// Configuration
1111
const config = defineMetabaseAuthConfig({
1212
metabaseInstanceUrl: import.meta.env.VITE_METABASE_INSTANCE_URL,
13-
authProviderUri: import.meta.env.VITE_AUTH_PROVIDER_URI,
1413
});
1514

1615
const questionId = 24;

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
MB_JWT_SHARED_SECRET: "${METABASE_JWT_SHARED_SECRET}"
1212
MB_SETUP_TOKEN: "${PREMIUM_EMBEDDING_TOKEN}"
1313
MB_PREMIUM_EMBEDDING_TOKEN: "${PREMIUM_EMBEDDING_TOKEN}"
14+
MB_JWT_IDENTITY_PROVIDER_URI: "http://localhost:${AUTH_PROVIDER_PORT}/sso/metabase"
1415
healthcheck:
1516
test: curl --fail -X GET -I "http://localhost:${MB_PORT}/api/health" || exit 1
1617
interval: 15s
@@ -30,12 +31,10 @@ services:
3031
dockerfile: ./client/Dockerfile
3132
args:
3233
VITE_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
33-
VITE_AUTH_PROVIDER_URI: "http://localhost:${AUTH_PROVIDER_PORT}/sso/metabase"
34-
WATCH: '${WATCH}'
34+
WATCH: "${WATCH}"
3535
environment:
3636
CLIENT_PORT: "${CLIENT_PORT}"
3737
VITE_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
38-
VITE_AUTH_PROVIDER_URI: "http://localhost:${AUTH_PROVIDER_PORT}/sso/metabase"
3938
ports:
4039
- "${CLIENT_PORT}:${CLIENT_PORT}"
4140
volumes:

metabase/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM metabase/metabase-enterprise:v1.54.x
1+
FROM metabase/metabase-enterprise:v1.55.x
22

33
COPY ./metabase /app/
44
COPY ./local-dist /app/local-dist

server/index.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
const express = require('express');
1+
const express = require("express");
22
const app = express();
3-
const dotenv = require('dotenv').config({ path: '../.env' });
4-
const cors = require('cors');
3+
const dotenv = require("dotenv").config({ path: "../.env" });
4+
const cors = require("cors");
55
const jwt = require("jsonwebtoken");
66

7-
app.get('/', (req, res) => {
8-
res.send('Hello from our server!')
9-
})
7+
app.get("/", (req, res) => {
8+
res.send("Hello from our server!");
9+
});
1010

11-
const AUTH_PROVIDER_PORT = process.env.AUTH_PROVIDER_PORT
12-
const METABASE_INSTANCE_URL = process.env.METABASE_INSTANCE_URL
13-
const METABASE_JWT_SHARED_SECRET = process.env.METABASE_JWT_SHARED_SECRET
11+
const AUTH_PROVIDER_PORT = process.env.AUTH_PROVIDER_PORT;
12+
const METABASE_INSTANCE_URL = process.env.METABASE_INSTANCE_URL;
13+
const METABASE_JWT_SHARED_SECRET = process.env.METABASE_JWT_SHARED_SECRET;
1414

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

1717
app.get("/sso/metabase", async (req, res) => {
18-
1918
// Usually, you would grab the user from the current session
2019
// Here it is hardcoded for demonstration purposes
2120
// Example:
@@ -24,15 +23,15 @@ app.get("/sso/metabase", async (req, res) => {
2423
email: "rene@example.com",
2524
firstName: "Rene",
2625
lastName: "Descartes",
27-
group: "Customer"
28-
}
26+
group: "Customer",
27+
};
2928

3029
if (!user) {
3130
console.log("no user");
3231
return res.status(401).json({
33-
status: 'error',
34-
message: 'not authenticated',
35-
})
32+
status: "error",
33+
message: "not authenticated",
34+
});
3635
}
3736

3837
const token = jwt.sign(
@@ -44,28 +43,36 @@ app.get("/sso/metabase", async (req, res) => {
4443
exp: Math.round(Date.now() / 1000) + 60 * 10, // 10 minutes expiration
4544
},
4645
// This is the JWT signing secret in your Metabase JWT authentication setting
47-
METABASE_JWT_SHARED_SECRET
48-
)
49-
const ssoUrl = `${METABASE_INSTANCE_URL}/auth/sso?token=true&jwt=${token}`
50-
console.log('Hitting MB SSO endpoint', ssoUrl);
46+
METABASE_JWT_SHARED_SECRET,
47+
);
48+
49+
if (req.query.response === "json") {
50+
return res
51+
.status(200)
52+
.set("Content-Type", "application/json")
53+
.send({ jwt: token });
54+
}
55+
56+
const ssoUrl = `${METABASE_INSTANCE_URL}/auth/sso?token=true&jwt=${token}`;
57+
console.log("Hitting MB SSO endpoint", ssoUrl);
5158

5259
try {
53-
const response = await fetch(ssoUrl, { method: 'GET' })
54-
const session = await response.text()
60+
const response = await fetch(ssoUrl, { method: "GET" });
61+
const session = await response.text();
5562

56-
console.log("Received session", session)
57-
return res.status(200).set("Content-Type", "application/json").end(session)
63+
console.log("Received session", session);
64+
return res.status(200).set("Content-Type", "application/json").end(session);
5865
} catch (error) {
5966
if (error instanceof Error) {
6067
res.status(401).json({
61-
status: 'error',
62-
message: 'authentication failed',
68+
status: "error",
69+
message: "authentication failed",
6370
error: error.message,
64-
})
71+
});
6572
}
6673
}
67-
})
74+
});
6875

6976
app.listen(AUTH_PROVIDER_PORT, () => {
70-
console.log(`server listening on port ${AUTH_PROVIDER_PORT}`)
71-
})
77+
console.log(`server listening on port ${AUTH_PROVIDER_PORT}`);
78+
});

0 commit comments

Comments
 (0)