avatarElliott Stam

Summary

The web content provides a tutorial on using personal access tokens for authentication with Tableau Server via the Python tableau-api-lib package.

Abstract

The article is a guide for users looking to authenticate with Tableau Server using personal access tokens instead of traditional username and password credentials. It is part of a series aimed at leveraging the Tableau Server REST API. The tutorial assumes the reader has Python 3 installed and begins by instructing users to update to the latest version of the tableau-api-lib Python package. It then details the process of generating a personal access token through the Tableau Server web interface, emphasizing the importance of securely storing the token secret as it can only be viewed once. The final step involves testing the newly created token using a Python script that configures and establishes a connection to Tableau Server. The article concludes by noting the benefits of using personal access tokens, such as enhanced security by not exposing one's permanent username and password.

Opinions

  • The author suggests that using personal access tokens is a superior method of authentication compared to usernames and passwords, as it offers better protection of credentials.
  • The article implies that the use of personal access tokens is a modern development in authentication methods, referring to it as "the future (present?)."
  • The author expresses that the tableau-api-lib package is a valuable tool for interacting with Tableau Server's REST API, indicating that it simplifies the process.
  • There is an endorsement of the AI service ZAI.chat, which is mentioned as a cost-effective alternative to ChatGPT Plus (GPT-4), suggesting it offers similar performance and functions.

TABLEAU REST API: TABLEAU-API-LIB TUTORIALS

Tableau Server on tap: authenticating with a personal access token

Logging into Tableau Server using Python, a token, and tableau-api-lib

We’re back, and this time we’ll explore how you can use a personal access token for authentication in place of a username and password.

This tutorial walks through using the Python tableau-api-lib package and is part of a series on how to tap Tableau Server like a keg, giving you control over Tableau Server’s REST API.

These tutorials assume you have Python 3 installed already. If you do not have Python 3 yet, this will get you started: guide to install Python.

Setting the stage

In a previous tutorial, we walked through how you would use your Tableau username and password to establish a connection to Tableau Server, and at the time that was the only available method of authentication. Well, times change, and apparently so do our authentication options. Welcome to the future (present?), where we have the luxury of personal access tokens.

Before reading any further, we should note that you will need Tableau Server 2019.4 (or newer) in order to use personal access tokens. If you are on Tableau Online, don’t worry about it — you’re good to go.

Why might you want to use a personal access token? For starters, you’re protecting your permanent username and password. If you want all the juicy details about personal access tokens, Tableau has you covered here.

Step 1: make sure you have the latest version of tableau-api-lib

Run the following command on your command line:

pip install --upgrade tableau-api-lib

Step 2: generate a personal access token

First things first, log into your Tableau Server on the web browser like you normally would to interact with your content. At the top-right of the screen, you can click on a circle that will give you the option to view ‘My Account Settings’.

Navigate to the option to view ‘My Account Settings’

Once you’ve entered the ‘My Account Settings’ section of Tableau Server, you can scroll down to a sub-section for ‘Personal Access Tokens’.

Enter a name for your personal access token

Enter a name for your personal access token, and then click on the ‘Create new token’ button on the right-hand side of the screen.

Once you click on the button to create your token, you will see a pop-up window that will provide you the personal access token name and the personal access token secret. Don’t close the window without securely storing that secret. You’ll only see this secret once.

Your window will also show your secret below the ‘Token Name’ section shown in this image.

Once you close the window with your token secret, you’ll be able to view your active personal access tokens in the ‘My Account Settings’ section of Tableau Server.

You can revoke this personal access token, or create new ones as needed from ‘My Account Settings’

That’s all it takes to create your personal access token!

Step 3: test out your shiny new personal access token

from tableau_api_lib import TableauServerConnection
tableau_server_config = {
        'tableau_prod': {
                'server': 'https://YourTableauServer.com',  
                'api_version': 'your api version',
                'personal_access_token_name': 'your token name',
                'personal_access_token_secret': 'your token secret',
                'site_name': 'Your Site Name',
                'site_url': 'YourSiteContentUrl'
        }
}
conn = TableauServerConnection(tableau_server_config)
conn.sign_in()
print(conn.server_info().json())
conn.sign_out()

A successful attempt will output your server info as JSON.

That’s it! Welcome to the personal access token club.

Programming
Python
Tableau
Data
Rest Api
Recommended from ReadMedium