Skip to content

Type 2: include data about PAT expiry #1197

Open

Description

@kykrueger

Summary

When authenticating with a personal access token (PAT) a duration until the expiry of the token is returned by the login request.
This information is dropped by the python client, yet would be useful to have it logged as a warning when the expiration date is near.

Description

As users of the python client, we have automated some data-engineering tasks, and authenticate with PATs.
Since the PATs may be configured to expire after a given period of time, it is necessary to keep track of when tokens need to be renewed.

The time until expiry is available in the following REST Request:
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_auth.htm#make-a-sign-in-request-with-a-personal-access-token

Since this request is already made as a part of the authentication process in the python client, I would like to extend the client to pass two optional parameters to the sign_in method:

  • token_expiry_warning_threshold: Optional[int] = 60
  • token_expiry_warning_callback: Optional[Callable[[str], None]]

The provided threshold should be an integer which represents days. If the token is set to expire in less days than in the threshold, a warning should be logged. I think 60 days is a sane default given the default expiration period is after 1 year.
A callable may also be provided which will be called with the string containing the time until expiry as received from the API. Its format is "days:hours:seconds".

Activity

  1. kykrueger commented on Feb 21, 2023

    @kykrueger
    ContributorAuthor

    I'm willing to add this myself

  2. kykrueger commented on Feb 21, 2023

    @kykrueger
    ContributorAuthor

    I'm now unsure if the value returned from the login request contains the time until the PAT expires, or the session token. Could someone confirm which of the two it is, if it is the later, then this feature request would require an API change.

  3. jacalata commented on Feb 22, 2023

    @jacalata
    Contributor

    This will require an API change, but it's already a known customer request so it might be in the works.

    From https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#sign_in
    An estimatedTimeToExpiration value is returned when you sign in using a PAT. The value represents the approximate time until the token returned from the PAT sign in will expire

  4. kykrueger commented on Feb 28, 2023

    @kykrueger
    ContributorAuthor

    Thanks for the update!
    Could you help me find a link to the customer request, so that we can get an update here once the server-side-update is complete?

    That way we can get started on this once the blocker is out of the way.

  5. jacalata commented on Mar 1, 2023

    @jacalata
    Contributor

    Hmm I'm not sure there is one, but if I find it I will add it here.

  6. changed the title [-]Type 1: support a REST API: Warning about PAT expiry[/-] [+]Type 2: include data about PAT expiry[/+] on Mar 27, 2023
  7. mtsadler-branch commented on Oct 10, 2023

    @mtsadler-branch

    @jacalata any update on whether expiration_date will be added to response when calling server.auth.sign_in()?

    It's already a manual effort to refresh an expired token.

    But it would be nice to have this expiration_date, so we can preemptively alert our team that the token is expiring.

    The best solutions our team has found:

    • (Proactive) Hardcode the "known" expiration_date in our logic, and alert when that date is approaching
    • (Reactive) Try-Except for ServerResponseError when calling server.auth.sign_in(), to raise alert about expired token

    Note that:

    • the first solution requires code changes (every time our token expires)
    • the second solution means our process breaks (every time our token expires)

    CC @aharcarik-branch

  8. jacalata commented on Sep 20, 2024

    @jacalata
    Contributor

    This has been implemented server-side (in List Personal Access Tokens), but we haven't got it in tsc yet.

  9. github-actions commented on Aug 18, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. If this is still relevant, please comment to keep it open.

  10. jacalata commented on Aug 25, 2026

    @jacalata
    Contributor

    Rechecked against current TSC — still a gap. Auth.sign_in at tableauserverclient/server/endpoint/auth_endpoint.py:69-94 parses the sign-in response but drops estimatedTimeToExpiration, and there is no personal_access_tokens endpoint wrapping List Personal Access Tokens (which exposes expiration server-side). Either surface estimated_time_to_expiration off sign-in and/or add a server.personal_access_tokens endpoint. Labeling as enhancement.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions