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

Prepare for HTTP Basic Auth deprecation #144

Closed
matkoniecz opened this issue Mar 19, 2023 · 10 comments · Fixed by #149
Closed

Prepare for HTTP Basic Auth deprecation #144

matkoniecz opened this issue Mar 19, 2023 · 10 comments · Fixed by #149

Comments

@matkoniecz
Copy link
Contributor

https://www.openstreetmap.org/user/pnorman/diary/401157

The Operations Working Group is looking at what it take to deprecate HTTP Basic Auth and OAuth 1.0a in favour of OAuth 2.0 on the main API in order to improve security and reduce code maintenance.

it seems that it is not happening soon but...

#113 (comment)

the library uses basic auth by default, but by allowing to pass a http session, it should be possible to enable OAuth. If I have a little spare time, I'll trs to come up with some example code. Then we can adapt the library if needed.

@metaodi
Copy link
Owner

metaodi commented Mar 20, 2023

Here is an example for Google OAuth2 using requests-oauthlib: https://requests-oauthlib.readthedocs.io/en/latest/examples/google.html

So it's possible to create a session object with OAuth (e.g. from requests_oauthlib import OAuth2Session) and then pass this session to osmapi. I'll create an example to see how it works. And then some documentation about how to create your own OAuth application on openstreetmap.org. This should all be straightforward.

@metaodi metaodi mentioned this issue Jul 17, 2023
@metaodi
Copy link
Owner

metaodi commented Jul 17, 2023

@matkoniecz I finally got the time to create an example using OAuth 2.0 (see PR #149).

@metaodi
Copy link
Owner

metaodi commented Jul 17, 2023

There is now an example here: https://github.com/metaodi/osmapi/blob/develop/examples/oauth2.py

@matkoniecz
Copy link
Contributor Author

There is now an example here: https://github.com/metaodi/osmapi/blob/develop/examples/oauth2.py

Do I need to do this on every script run?

And if user can save oauth2client parameters (to build it), auth_code and redirect_uri and recreate connection without manual interaction - maybe mention it in some comment?

@metaodi
Copy link
Owner

metaodi commented Jan 12, 2024

@matkoniecz I should test that. But in theory the token should be valid for some time.

@matkoniecz
Copy link
Contributor Author

some? So I will need to keep going through this dance manually? Arghhh.

Though for some reason they really want to deprecate it per openstreetmap/operations#867

@matkoniecz
Copy link
Contributor Author

openstreetmap/operations#867 (comment) mentions something that may or may not be applicable

@metaodi
Copy link
Owner

metaodi commented Jan 15, 2024

I did a quick test, and currently the tokens do not have an expiry date, so it seems you can use a token forever unless a user revokes it (e.g. here https://master.apis.dev.openstreetmap.org/oauth2/authorized_applications).

So you have to do this dance once, save the token and then reuse it instead of username/password.

@metaodi metaodi reopened this Jan 15, 2024
@metaodi
Copy link
Owner

metaodi commented Jan 15, 2024

Here is a gist of the script I use: https://gist.github.com/metaodi/df380794ba00df5e73423682231e9ba2

@metaodi
Copy link
Owner

metaodi commented Mar 20, 2024

Since I added a new (more realistic) example script incl. saving and re-using a token, I consider this issue as resolved.

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

Successfully merging a pull request may close this issue.

2 participants