Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Get Data from Tableau embedding v3 with JWT token #58

Open
saadbahir opened this issue Jan 20, 2023 · 0 comments
Open

Unable to Get Data from Tableau embedding v3 with JWT token #58

saadbahir opened this issue Jan 20, 2023 · 0 comments

Comments

@saadbahir
Copy link

Hello

I am using tableau embedding v3 in JS with a generated JWT token but I am unable to retrieve the worksheet data.
I pull the data using this piece of code

const worksheets = viz.workbook.activeSheet.worksheets
for (const worksheet of worksheets) {
  const tables = await worksheet.getUnderlyingTablesAsync()
  for (const table of tables) {
    const tableId = table.id
    console.log('table id', tableId)
    const dataTable = await worksheet.getUnderlyingTableDataAsync(
      tableId,
      options
    )
    console.log(dataTable)
  }
  break
}

But I encounter this error

WebCommandHandler: Command 'api-get-worksheet-logical-table-ids' (namespace: 'tabdoc') encountered error: 'api-get-worksheet-logical-table-ids: , status: 401, textStatus: error'

I generated the token using this method

export function getTableauToken(userName) {
  const header = {
    alg: 'HS256',
    kid: process.env.REACT_APP_CONNECTED_APP_SECRET_ID, // Tableau require it in header. Ref: https://help.tableau.com/current/online/en-us/connected_apps.htm
    // @ts-expect-error `iss` is needed as per Tableau docs but there is type mismatch as per `jsonwebtoken` library
    iss: process.env.REACT_APP_CONNECTED_APP_CLIENT_ID
  }
  console.log(header)
  const uuid = window.crypto.randomUUID()
  const token = sign(
    {
      scp: [
        'tableau:views:embed',
        'tableau:metrics:embed',
        'tableau:content:read',
        'tableau:views:embed_authoring'
        // 'tableau:workbooks:read',
        // 'tableau:datasources:*',
        // 'tableau:tasks:run'
      ] // scope
    },
    process.env.REACT_APP_CONNECTED_APP_SECRET_VALUE,
    {
      audience: 'tableau', // must be 'tableau'
      subject: userName, // Username as per Tableau platform
      issuer: process.env.REACT_APP_CONNECTED_APP_CLIENT_ID, // Tableau require it in header, but there is no attribute in header for 'issuer', so added here.
      jwtid: uuid, // The JWT ID claim provides a unique identifier for the JWT
      expiresIn: 600, // 10 minutes (max limit set by Tableau)
      header
    }
  )
  return token
}

​I added a connected app with unrestricted embedding and I have generated the token associated with the admin user.

When I disable the token prop from the tableau-viz container, I complete the authentication using the Tableau sign-in prompt and I am able to get the data with the same JS code above

Am I missing any specific scope?

Thank you

Saad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants