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

refresh token workflow #516

Open
martibosch opened this issue Aug 3, 2023 · 1 comment
Open

refresh token workflow #516

martibosch opened this issue Aug 3, 2023 · 1 comment

Comments

@martibosch
Copy link

Hello! I am using OAuth2Session as follows:

    with open(token_filepath) as src:
        token = json.load(src)

    def token_saver(token):
        with open(token_filepath, "w") as dst:
            json.dump(token, dst)

    session = requests_oauthlib.OAuth2Session(
        client_id,
        token=token,
        auto_refresh_url=REFRESH_TOKEN_URL,
        auto_refresh_kwargs={"client_id": client_id, "client_secret": client_secret},
        token_updater=token_saver,
    )

    response = session.get(
        SOME_URL,
        data=some_dict,
    )
    response.raise_for_status()

It works at first but once the token expires, a 403 error is raised at the last line. The logs revel that the self._client.add_token call in the OAuth2Session.request does not raise any TokenExpiredError, so the token is not updated and then I get the 403 error.

Am I missing something, or is this a peculiarity of the web service and I should thus implement an ad-hoc solution for my use case?

Thank you. Best,
Martí

@RileyEv
Copy link

RileyEv commented Feb 2, 2024

Did you ever solve this? I'm seeing exactly the same thing

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

2 participants