Reputation: 473
I am creating an application to interact with Tableau's REST API.
I am using Tableaus Online Server to host the workbooks/groups/users etc.
What I need is a way to let a user sign in and then interact with the REST API without having to store a username and password for server authentication.
Currently, if someone wanted to get a list of workbooks, they would need the following code
import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD', site_id='CONTENTURL')
server = TSC.Server('https://SERVER_URL', use_server_version=True)
server.auth.sign_in(tableau_auth)
Tableau does use personal access tokens and I can authenticate like this
import tableauserverclient as TSC
tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN-NAME', 'TOKEN-VALUE', site_id='CONTENTURL')
server = TSC.Server('https://SERVER_URL', use_server_version=True)
server.auth.sign_in(tableau_auth)
The problem I am running into is that signing in with a username and password only returns a token value. I don't think this is meant to be the same as the personal access token, but can I use this token value to authenticate the user and do other actions with the REST API?
The structure of the signin response is
{
credentials: {
site: {id: ...},
user: {id: ...},
token: tokenValue
}
}
You can also create a personal access token manually on the tableau online server. Is there a way to get this value after signing in with a username and password?
Upvotes: 2
Views: 2000
Reputation: 131
Should anyone else comes across this, the solution is that it should be used in a 'with' block (came across this q while answering another).
The token they're referencing is for something different than what I think they're trying to do, they're mistakenly after the temp token that's generated with the call, which you don't usually need for anything TSC related. The PersonalAccessToken is something created in the web admin for a user and the preferred way to handle auth for automated actions. Easy fix though once generated.
import tableauserverclient as TSC
server = TSC.Server('https://SERVER_URL', use_server_version=True)
tableau_auth = TSC.TableauAuth(
'USERNAME',
'PASSWORD',
site_id='CONTENTURL'
)
#Below would be equally fine
# tableau_auth = TSC.PersonalAccessTokenAuth(
# 'TOKEN-NAME',
# 'TOKEN-VALUE',
# site_id='CONTENTURL')
with server.auth.sign_in(tableau_auth): # either is used here
# Perform any desired authenticated actions here
# e.g. Getting a workbook object
workbook = server.workbooks.get_by_id("xxxx")
Upvotes: 0
Reputation: 473
Okay, so I kinda figured it out like a few minutes after posting this. And if anyone else gets a little confused when working with the Tableau REST API and their authentication, I hope this helps a little bit.
There is a python package called tableauserverclient and it's supposed to make interacting with the REST API easier. It does, except I don't believe there is a way to pass values to the header of the request. Which is how they manage the access tokens after signing in (and the personal access token is a completely separate thing).
So, when a user signs in, they receive an access token that can be used later to authenticate other services. But, the token needs to be passed in the header as the X-Tableau-Auth value.
So, while the TSC library simplifies and python-izes some of the requests, it doesn't allow you to utilize the access token from sign in.
Upvotes: 1