0

I am trying to embed dashboard from my app's instance of superset, I am unable to view the dashboard on my application,

I am getting 401 unauthorized error, even if i am sending the authorization header which i am getting from the fetch_guest_token() function.

Where I am I going wrong? Or is there any other way to set the authorization header?

Response: {
"msg": "Missing Authorization Header" 
}

Request URL: https://aether.ithena.io/api/v1/dashboard/
Request Method: GET
Status Code: 401 UNAUTHORIZED
async function embedDashboard() {
    try {
        updateStatus('Starting dashboard embed...');
        console.log('Starting dashboard embed...');
        
        const embedConfig = {
            id: DASHBOARD_CONFIG.id,
            supersetDomain: DASHBOARD_CONFIG.supersetDomain,
            mountPoint: document.getElementById("superset-container"),
            fetchGuestToken: fetchGuestToken, //auth 
            
            dashboardUiConfig: {
                hideTitle: false,
                hideTab: false,
                hideChartControls: false,
                filters: {
                    expanded: false,
                    visible: true
                }
            }
        };
        
        console.log('Embedding dashboard with config:', embedConfig);
        
        const dashboard = await supersetEmbeddedSdk.embedDashboard(embedConfig);
        
        console.log('Dashboard embedded successfully!', dashboard);
        updateStatus('Dashboard loaded successfully!', 'success');
        
    }
async function fetchGuestToken() {
    try {
        updateStatus('Requesting guest token...');
        console.log('Fetching guest token from Node.js server...');
        
        const response = await fetch(`${DASHBOARD_CONFIG.serverUrl}/api/guest-token`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                user_info: {
                    username: "guest_user",
                    firstName: "Guest",
                    lastName: "User",
                    roles: ["Admin"]
                },
                resources: [{ 
                    type: "dashboard", 
                    id: DASHBOARD_CONFIG.id 
                }],
                "rls": []
            })
        });
        
        if (!response.ok) {
            const errorData = await response.json();
            throw new Error(`Server error: ${errorData.error || response.status}`);
        }
        
        const data = await response.json();
        console.log('Guest token received');
        updateStatus('Guest token received, embedding dashboard...', 'success');
        
        return data.token;
        
    } catch (error) {
        console.error('Failed to fetch guest token:', error);
        updateStatus(`Failed to get guest token: ${error.message}`, 'error');
        throw error;
    }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.