Skip to content

Tesla.authorized doesn't detect a stale-but-present invalid token #178

Description

@cjw296

Tesla.authorized is inherited unchanged from requests_oauthlib.OAuth2Session:

@property
def authorized(self):
    return bool(self.access_token)

This only tells you a token exists in the cache, not that it's still valid, so once
cache.json holds any token, even one whose refresh_token has expired, authorized still returns
True, fetch_token()/api() skip the interactive flow, and the first API call
instead falls into automatic token refresh, which fails with
oauthlib.oauth2.rfc6749.errors.LoginRequired: (login_required) The refresh_token is invalid.

My workaround is to force-clear state first:

tesla.token = {}
del tesla.access_token
tesla.fetch_token()

Feels like .authorized should do some kind of a check on this front, but doesn't feel like it would be lightweight.
Not sure what to suggest, but wanted to log it in case others encounter it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions