Not possible to include HTTP Basic Auth data in auto_refresh_kwargs
See original GitHub issueHello.
I feel that it should be possible to add auth (as supported by requests, in tuple form) to auto_refresh_kwargs in OAuth2Session. Right now both possible situations are bad:
- adding 
authtoauto_refresh_kwargsresults in adding it to the body of the refresh request; - adding 
authtoOAuth2Sessiondirectly would result in it being passed to all subsequent requests made with that session, which is not what I want. 
I would like to add it to OAuth2Session in the way that would ensure that any automatic future calls to refresh_token will have auth passed as well, so it would end up being passed to requests and handled as HTTP Basic Auth.
PS A workaround to do it would be, for example:
def wrap(func):
    def wrapper(*args, **kwargs):
        kwargs['auth'] = ('user', 'password')
        return func(*args, **kwargs)
    return wrapper
session.refresh_token = wrap(session.refresh_token)
Issue Analytics
- State:
 - Created 4 years ago
 - Comments:6
 
Top Results From Across the Web
Can you pass user/pass for HTTP Basic Authentication in URL ...
It is indeed not possible to pass the username and password via query parameters in standard HTTP auth. Instead, you use a special...
Read more >HTTP authentication - MDN Web Docs - Mozilla
This page is an introduction to the HTTP framework for authentication, and shows how to restrict access to your server using the HTTP...
Read more >HTTP basic authentication - IBM
HTTP basic authentication is a simple challenge and response mechanism with which a server can request authentication information (a user ID ...
Read more >HTTP basic authentication not working in python 3.4
I am trying to login to a REST API using HTTP Basic Authentication but it is not working and giving the error
Read more >Basic Authentication - Swagger
Basic Authentication. Basic authentication is a simple authentication scheme built into the HTTP protocol. The client sends HTTP requests with the Authorization ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m also desiring this functionality. The Xero API requires Basic Auth for the refresh token: https://developer.xero.com/documentation/oauth2/auth-flow#refresh . I’m currently having to work around auto-refresh not working by caching the token expired exceptions everywhere where the session is used. Not very elegant.
The PR #433 looks like a relatively clean solution that doesn’t change the API or backwards compatibility of
refresh_token.What’s the status on this? It seems like there may be solutions but I’m not smart enough to understand what is being proposed. I thought just setting the auth property to the basic authentication header would work but then of course subsequent API requests that need the access token as the authentication header fail. More details on my situation here: https://stackoverflow.com/questions/65874797/include-authorization-in-a-oauth2session-for-requests-oauthlib
As is, this example in the docs (below) doesn’t seem like it will actually work if the API server wants a basic authentication header for the refresh token.
https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#third-recommended-define-automatic-token-refresh-and-update