requests / requests-oauthlib

OAuthlib support for Python-Requests!
https://requests-oauthlib.readthedocs.org/
ISC License
1.71k stars 421 forks source link

refactor: Add support for auto-refreshing token without refresh token #526

Open dabla opened 5 months ago

dabla commented 5 months ago

Hello,

This is a pull request based on the changes made by @denizdogan but which finally never got merged due to missing tests.

Here is the original explaination:

This is a basic idea on how to fix https://github.com/requests/requests-oauthlib/issues/260 since nothing has happened to the issue in three years. Let's get a discussion going, because this is a hindrance to me in almost every OAuth2 implementation I make using this library and it's clear that lots of other people have the same issue.

So the idea is to add a new constructor parameter which I currently call auto_refresh_type, it can be either "refresh_token" (which will do exactly what it does today) or "access_token" (which will just get a new access token as you normally do).

It's not a beautiful design by any means, but I intentionally tried to keep the diff as minimal as possible without any major refactorings, which would introduce breaking changes and make it more difficult to get this functionality out there.

I've done some minor refactoring but also added 2 tests which test both cases when the update_token method is invoked.

Kind regards, David

jtroussard commented 3 months ago

@dabla Is it possible to update this PR/fix conflicts. This will kick off the test runners and I will have a look and try to get this merged.

jtroussard commented 3 months ago

for documentation purposes, linking these related resources.

394 #260

issue and pr related to previous attempts to get this feature merged.