server-client-python
server-client-python copied to clipboard
Can't see workbook connections using JWT
I'm moving from using a PAT to using a JWT. The following code worked with a PAT but I can't seem to get it to work using a JWT. I've scoped everything and it says in the Tableau docs that you should be able to update connection details with a JWT. I'm getting an unauthorized error for this. I was able to do a number of other operations with the JWT, just not this one.
import tableauserverclient as TSC
import jwt
from datetime import timezone, datetime, timedelta
import uuid
jwt_token = jwt.encode(
{
"iss": client_id,
"exp": datetime.utcnow() + timedelta(minutes=10),
"jti": str(uuid.uuid4()),
"aud": "tableau",
"sub": "[email protected]",
"scp": ["tableau:*"]}, ###everything in scope
secret_key,
algorithm = "HS256",
headers = {
'kid': secret_id,
'iss': client_id
}
)
tableau_auth = TSC.JWTAuth(token, 'my_site')
server = TSC.Server('https://us-east-1.online.tableau.com/', use_server_version=True)
with server.auth.sign_in(tableau_auth):
for wb in TSC.Pager(server.workbooks):
server.workbooks.populate_connections(wb)
for connection in wb.connections: #### breaks here on wb.connections<<<<<
creds = get_correct_creds(connection)
if (creds):
connection.username = creds["user"]
connection.password = creds["password"]
server.workbooks.update_conn(wb, connection)
Query Workbook Connections does not show as supported for JWT, nor does Update Workbook Connection.
@jorwoods it looks like Update Workbook Connection does support JWT.
The same block is not present for Query Workbook Connections though. So if no JWT scope is listed it is not supported? I don't see anything explicitly saying there is no JWT support. As far as permissions go it just mentions 'Read' which aligns to a workbook JWT scope, but must mean something different.
Seems odd that you could update a connection but you can't query them. Ultimately you can still download the workbook with JWT which would provide access to connection information, right?
Ahh, update does support JWT. But yes, if not explicitly listed as supporting JWT, an endpoint does not support it. I agree it is strange that update connection is supported but querying the connections is not.
Downloading the workbook and inspecting the XML would give some of the information needed, but not the connection id.