OAuth2Session doesn't use token if netrc is present
See original GitHub issueThe Heroku Toolbelt client uses a .netrc file to store its credentials locally. When using OAuth2Session, giving a properly-formed token to the constructor, the auth property on the session is not set, and requests goes and looks for a netrc file to add them in automatically when the request is made. When we have set the token, this really needs to not happen.
The “ideal” fix would be to have the OAuth2Session.auth property set to OAuth2. I definitely don’t know the complexities of how difficult this is, but this bug makes OAuth2Session unusable for me, and I’m having to drop down to using OAuth2 auth directly instead for my use-case.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Missing access Token parameter with OAuth2Session, but ...
The api I'm hitting isn't public, so I'll do my best to provide context even if you can't directly reproduce. Here's what works...
Read more >The .netrc file (GNU Inetutils)
Identify a user on the remote machine. If this token is present, the auto-login process will initiate a login using the specified name....
Read more >Git .netrc file authentication issue - Stack Overflow
The ~/.netrc (or %HOME%\_netrc on Windows) file isn't enough. It is best to use that file encrypted, with gpg + netrc alone, as...
Read more >Simple OAuth2 with Password and Bearer - FastAPI
It doesn't matter if it has other characters like : or if it is a URL. ... and use it as a dependency...
Read more >.netrc - Everything curl
Note that if this token is present in the .netrc file you really should make sure the file is not readable by anyone...
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

That’s certainly possible. Worth seeing how that looks in the code, at any rate.
I was thinking that those cases could be handled the same as with a standard
Session, by initializing it with the No-op auth, and then setting the auth after initialization. This is exactly what’s required from a normalSessionanyway.Are you saying that there’s further complexity within requests-oauthlib that makes that pattern unsuitable?