I followed the instructions for embedding an interactive Metabase dashboard from this link, and I wrote a Java/Spring microservice following the instructions. Here's the code:
@GetMapping("/ssometabase")
public void ssoToMetabase(HttpServletResponse response, @RequestParam(required = false) String return_to)
throws IOException {
String email = "user@example.com"; /
String firstName = "John";
String lastName = "Doe";
User user = new User();
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
String token = jwtService.signToken(user);
String redirectUrl = metabaseUrl + "/auth/sso?jwt=" + token;
if (return_to != null) {
redirectUrl += "&return_to=" + URLEncoder.encode(return_to, StandardCharsets.UTF_8.toString());
}
System.out.println(redirectUrl);
response.sendRedirect(redirectUrl);
}
@GetMapping("/analytics")
public void showAnalytics(HttpServletRequest request, HttpServletResponse response) throws IOException {
String METABASE_DASHBOARD_PATH = "/dashboard/3?tab=7-circulation";
String iframeUrl = "/ssometabase?return_to=" + METABASE_DASHBOARD_PATH;
String html = "<iframe src=\"" + iframeUrl
+ "\" frameborder=\"0\" width=\"1280\" height=\"600\" allowtransparency=\"true\"></iframe>";
response.setContentType("text/html");
response.getWriter().write(html);
}
I followed the instructions for embedding an interactive Metabase dashboard from this link, and I wrote a Java/Spring microservice following the instructions. Here's the code:
@GetMapping("/ssometabase")
public void ssoToMetabase(HttpServletResponse response, @RequestParam(required = false) String return_to)
throws IOException {
String email = "user@example.com"; /
String firstName = "John";
String lastName = "Doe";
User user = new User();
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
String token = jwtService.signToken(user);
String redirectUrl = metabaseUrl + "/auth/sso?jwt=" + token;
if (return_to != null) {
redirectUrl += "&return_to=" + URLEncoder.encode(return_to, StandardCharsets.UTF_8.toString());
}
System.out.println(redirectUrl);
response.sendRedirect(redirectUrl);
}
@GetMapping("/analytics")
public void showAnalytics(HttpServletRequest request, HttpServletResponse response) throws IOException {
String METABASE_DASHBOARD_PATH = "/dashboard/3?tab=7-circulation";
String iframeUrl = "/ssometabase?return_to=" + METABASE_DASHBOARD_PATH;
String html = "<iframe src=\"" + iframeUrl
+ "\" frameborder=\"0\" width=\"1280\" height=\"600\" allowtransparency=\"true\"></iframe>";
response.setContentType("text/html");
response.getWriter().write(html);
}
The problem is that when I call the /analytics
endpoint, it returns an iframe and then constantly calls the /ssometabase
endpoint in an infinite loop. I don't know what is causing this. For the JWT provider URI in the Metabase configuration, I set it to http://localhost:8080/ssometabase
, enabled embedding, and generated a token using the secret key with this method :
public String signToken(User user){
Map<String, Object> claims = new HashMap<>();
claims.put("email", user.getEmail());
claims.put("first_name", user.getFirstName());
claims.put("last_name", user.getLastName());
Date now = new Date();
long expirationTime = now.getTime() + 1000 * 60 * 10;
return Jwts.builder()
.setClaims(claims)
.setExpiration(new Date(expirationTime))
.signWith(SignatureAlgorithm.HS256, secretKey.getBytes())
.compact();
}
When I go to the redirect URL printed in the console, I can see the dashboard. Any help is welcome Embedding metabase using java