Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.example.controllers.dashboard;
import org.springframework.security.jwt.Jwt;
import org.springframework.security.jwt.JwtHelper;
import org.springframework.security.jwt.crypto.sign.MacSigner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = {"/dashboardUrl"})
public class DashboardController {
private final String METABASE_SITE_URL = "http://somehost/metabaseUrl";
private final String METABASE_SECRET_KEY = "SOME_SECRET_KEY";
@GetMapping("")
public DashboardParams indexAction() {
Jwt token = JwtHelper.encode("{\"resource\": {\"dashboard\": 1}, \"params\": {}}", new MacSigner(METABASE_SECRET_KEY));
String url = METABASE_SITE_URL + "/embed/dashboard/" + token.getEncoded() + "#theme=night&bordered=true&titled=true";
return new DashboardParams(url);
}
class DashboardParams {
private String url;
public DashboardParams(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.