Skip to content

Commit e2369eb

Browse files
authored
Merge pull request #1289 from tableau/jac/docs-jwt
2 parents 4e1d4d9 + ad6bcac commit e2369eb

1 file changed

Lines changed: 48 additions & 8 deletions

File tree

docs/sign-in-out.md

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ The first step to using the TSC library is to sign in to your Tableau Server (or
1010

1111
## Sign In
1212

13-
Signing in can be done two different ways:
13+
Signing in through tsc and the REST API can be done several different ways - in most cases only some of these options will be available, depending on your server configuration. You can see details of all the underlying APIs for authentication in the [REST API documentation](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_authentication.htm).
1414

15-
* Personal Access Tokens - In most cases this is the preferred method because it improves security by avoiding the need to use or store passwords directly. Access tokens also expire by default if not used after 15 consecutive days. This option is available for Tableau Server 2019.4 and newer. Refer to [Personal Access Tokens](https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm) for more details.
16-
* Username and Password - Direct sign in with account username and password.
17-
18-
Examples showing both of these cases are included below.
15+
Examples for all supported methods are included below.
1916

2017
**Note:** When you sign in, the TSC library manages the authenticated session for you. However, the validity of the underlying credentials token is limited by the maximum session length set on your Tableau Server (2 hours by default).
2118

2219
### Sign in with Personal Access Token
2320

21+
In most cases this is the preferred method because it improves security by avoiding the need to use or store passwords directly. Access tokens also expire by default if not used after 15 consecutive days. This option is available for Tableau Server 2019.4 and newer. Refer to [Personal Access Tokens](https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm) for more details.
22+
2423
To sign in to Tableau Server or Tableau Cloud with a personal access token, you'll need the following values:
2524

2625
Name | Description
@@ -50,7 +49,10 @@ server.auth.sign_out()
5049

5150
### Sign in with Username and Password
5251

53-
To sign in to Tableau Server or Tableau Cloud with a username and password, you'll need the following values:
52+
53+
Direct sign in with account username and password. (This is no longer allowed for Tableau Cloud)
54+
55+
To sign in to Tableau Server with a username and password, you'll need the following values:
5456

5557
Name | Description
5658
:--- | :---
@@ -73,7 +75,45 @@ server.auth.sign_in(tableau_auth)
7375
server.auth.sign_out()
7476
```
7577

76-
### Handling SSL certificates for Tableau Server
78+
### Sign in with JSON Web Token (JWT)
79+
80+
If you have Connected Apps enabled, you can create JSON Web Tokens and use them to authenticate over the REST API. To learn about Connected Apps, read the docs on [Tableau Connected Apps](https://help.tableau.com/current/server/en-us/security_auth.htm#connected-apps)
81+
82+
To sign in to Tableau Server or Tableau Cloud with a JWT, you'll need to have created a Connected App and generated the token locally (see [instructions to generate a JWT for your Connected App](https://help.tableau.com/current/server/en-us/connected_apps.htm#step-3-configure-the-jwt)):
83+
84+
class JWTAuth(Credentials):
85+
def __init__(self, jwt=None, site_id=None, user_id_to_impersonate=None):
86+
Name | Description
87+
:--- | :---
88+
JWT | The generated token value
89+
SITENAME | The same as described for personal access tokens
90+
SERVER_URL | The same as described for personal access tokens
91+
92+
This example illustrates using the above values to sign in with a JWT, do some operations, and then sign out:
93+
94+
```py
95+
import tableauserverclient as TSC
96+
97+
tableau_auth = TSC.JWTAuth('JWT', 'SITENAME')
98+
server = TSC.Server('https://SERVER_URL', use_server_version=True)
99+
server.auth.sign_in(tableau_auth)
100+
101+
# Do awesome things here!
102+
103+
server.auth.sign_out()
104+
```
105+
106+
107+
## Impersonation (Tableau Server only)
108+
On Tableau Server, users with a Server Administrator role can sign in through the REST API and 'impersonate' another user - this may be to validate server permissions, to investigate user problems, or to perform actions on behalf of the user. This can be done in tsc with any type of authentication by adding an extra parameter (`user_id_to_impersonate`) to the TableauAuth object creation
109+
110+
e.g
111+
tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITE_NAME', 'OTHER_USER_ID')
112+
tableau_auth = TSC.JWTAuth('JWT_VALUE', 'SITE_NAME', 'OTHER_USER_ID')
113+
tableau_auth = TSC.TSC.TableauAuth('USERNAME', 'PASSWORD', 'SITENAME')
114+
115+
116+
## Handling SSL certificates for Tableau Server
77117

78118
If you're connecting to a Tableau Server instance that uses self-signed or non-public SSL certificates, you may need to provide those as part of the sign in process. An example of this could be an on-premise Tableau Server that is using internally-generated SSL certificates. You may see an error like `SSL: CERTIFICATE_VERIFY_FAILED` if you connect with a Tableau Server but don't have the SSL certificates configured correctly.
79119

@@ -126,7 +166,7 @@ As shown in the examples above, the sign out call is simply:
126166
server.auth.sign_out()
127167
```
128168

129-
## Simplify by using Python with block
169+
## Simplify by using Python `with` block
130170

131171
The sign in/out flow can be simplified (and handled in a more Python way) by using the built-in support for the `with` block. After the block execution completes, the sign out is called automatically.
132172

0 commit comments

Comments
 (0)