Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to use Auto_refresh_url, Auto_refresh_kwargs and Token_updater on OAuth2UserHandler #1953

Open
fabge opened this issue Aug 29, 2022 · 3 comments

Comments

@fabge
Copy link

fabge commented Aug 29, 2022

I am trying to set up an automated token refresh flow. The documentation for tweepy.OAuth2UserHandler shows the following 3 entries:

Auto_refresh_url
Refresh token endpoint URL, must be HTTPS. Supply this if you wish the client to automatically refresh your access tokens.

Auto_refresh_kwargs
Extra arguments to pass to the refresh token endpoint.

Token_updater
Method with one argument, token, to be used to update your token database on automatic token refresh. If not set a TokenUpdated warning will be raised when a token has been refreshed. This warning will carry the token in its token argument.

However I cannot find a way to pass those arguments while instantiating from tweepy.OAuth2UserHandler. As far as I can see, the code has to be extended something like below. Notice the **kwargs keyword (could also be made more explicit).

class OAuth2UserHandler(OAuth2Session):
    """OAuth 2.0 Authorization Code Flow with PKCE (User Context)
    authentication handler

    .. versionadded:: 4.5
    """

    def __init__(self, *, client_id, redirect_uri, scope, client_secret=None, **kwargs):
        super().__init__(client_id, redirect_uri=redirect_uri, scope=scope, **kwargs)
        if client_secret is not None:
            self.auth = HTTPBasicAuth(client_id, client_secret)
        else:
            self.auth = None
@fabge
Copy link
Author

fabge commented Sep 10, 2022

Is there any guidance around this? It seems this feature is not working...
image

@slashtechno
Copy link

I'm also trying to use OAuth2 with a refresh token. It seems there are pull requests open at the moment which enable usage of a refresh token
At the time of writing:

@turkishmaid
Copy link

@fabge We can just hijack the code from PR #1806 :)
See here: #1912 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants