aws-sdk-js icon indicating copy to clipboard operation
aws-sdk-js copied to clipboard

when I call the generateEmbedUrlForRegisteredUser on a quicksight instance there are two error

Open qiangyi1 opened this issue 3 years ago • 2 comments

Confirm by changing [ ] to [x] below:

Describe the question 1. Request URL: https://quicksight.us-east-1.amazonaws.com/accounts/xxxxxxxxx/embed-url/registered-user Request Method: OPTIONS Status Code: 404 2. Request URL: https://quicksight.us-east-1.amazonaws.com/accounts/xxxxxxx/embed-url/registered-user Referrer Policy: strict-origin-when-cross-origin Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. the second error may cause by the first error. please help me to solve that. thanks!

qiangyi1 avatar Feb 17 '22 17:02 qiangyi1

Hi @qiangyi1 can you provide more information (with reproducible code) and follow this template so we can investigate more.

**Is the issue in the browser/Node.js?**
Browser/Node.js

**If on Node.js, are you running this on AWS Lambda?**

**Details of the browser/Node.js version**
Paste output of `npx envinfo --browsers` or `node -v`

**SDK version number**
Example: v2.466.0
* For browsers, the SDK version number is in the script tag <pre>src=".../aws-sdk-<b>2.466.0</b>.min.js"</pre>
* For Node.js, get SDK version by
  * running command `npm list aws-sdk` from your root directory
  * printing the output of `console.log(AWS.VERSION)` in your code where `AWS = require("aws-sdk");`
  * if running on Lambda and using SDK provided by Lambda runtime, you can find the SDK versions [here](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) 

**To Reproduce (observed behavior)**
Steps to reproduce the behavior (please share code or minimal repo)

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.

vudh1 avatar Feb 19 '22 01:02 vudh1

It is in the browser. I noted that It is the version of 2.1074.0. I do not use the script type to use the sdk.I install the npm module of sdk for If I want to use the quicksight normally I have to use the client of quicksight because the script type of sdk is not including the quicksight constructor to call. there are some commonts for the below code. I am glad for your team to solve the problem for me.Thanks very much.

browser version: google chrome Version 98.0.4758.102 (Official Build) (64-bit).

the code is reffered the below. //global.fetch = require('node-fetch'); I commont this line. import QuickSight from "aws-sdk/clients/quicksight.js"; //I add this for the quicksight constructor and replace AWS.Quicksight // to QuickSight. Before I call the generateEmbedUrlForRegisteredUser I call something about credentials and getOpenToken. // the code I refered come from this link .https://docs.aws.amazon.com/zh_cn/zh_cn/quicksight/latest/user/embedded-dashboards-for-authenticated-users-step-2.html. the javascript section. const AWS = require('aws-sdk');

function generateEmbedUrlForRegisteredUser( accountId, dashboardId, openIdToken, // Cognito-based token userArn, // registered user arn roleArn, // IAM user role to use for embedding sessionName, // Session name for the roleArn assume role getEmbedUrlCallback, // GetEmbedUrl success callback method errorCallback // GetEmbedUrl error callback method ) { const stsClient = new AWS.STS(); let stsParams = { RoleSessionName: sessionName, WebIdentityToken: openIdToken, RoleArn: roleArn }

stsClient.assumeRoleWithWebIdentity(stsParams, function(err, data) {
    if (err) {
        console.log('Error assuming role');
        console.log(err, err.stack);
        errorCallback(err);
    } else {
        const getDashboardParams = {
            "AwsAccountId": accountId,
            "ExperienceConfiguration": {
                "Dashboard": {
                    "InitialDashboardId": dashboardId
                }
            },
            "UserArn": userArn,
            "SessionLifetimeInMinutes": 600
        };

        const quicksightGetDashboard = new AWS.QuickSight({
            region: process.env.AWS_REGION,
            credentials: {
                accessKeyId: data.Credentials.AccessKeyId,
                secretAccessKey: data.Credentials.SecretAccessKey,
                sessionToken: data.Credentials.SessionToken,
                expiration: data.Credentials.Expiration
            }
        });

        quicksightGetDashboard.generateEmbedUrlForRegisteredUser(getDashboardParams, function(err, data) {
            if (err) {
                console.log(err, err.stack);
                errorCallback(err);
            } else {
                const result = {
                    "statusCode": 200,
                    "headers": {
                        "Access-Control-Allow-Origin": "*", // Use your website domain to secure access to GetEmbedUrl API
                        "Access-Control-Allow-Headers": "Content-Type"
                    },
                    "body": JSON.stringify(data),
                    "isBase64Encoded": false
                }
                getEmbedUrlCallback(result);
            }
        });
    }
});

}

qiangyi1 avatar Feb 20 '22 03:02 qiangyi1

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

github-actions[bot] avatar Mar 16 '23 00:03 github-actions[bot]