metaodi / osmapi

Python wrapper for the OpenStreetMap API
http://osmapi.metaodi.ch/
GNU General Public License v3.0
213 stars 41 forks source link

Use cli-oauth2 library for OAuth2 #168

Closed Zverik closed 3 months ago

Zverik commented 4 months ago

This is a follow-up to #144.

Given we won't have basic auth in a week, I suggest using my library cli-oauth2.

The example code in the readme would like much simpler with it:

import osmapi
from oauthcli import OpenStreetMapAuth

client_id = '<client_id>'
secret_id = '<client_secret>'
auth = OpenStreetMapAuth(
    client_id, secret_id, ['read_prefs', 'write_map']
).auth_server()

api = osmapi.OsmApi(
    api='https://api.openstreetmap.org', 
    session=auth.session)

with api.Changeset({"comment": "My first test"}) as changeset_id:
    print(f"Part of Changeset {changeset_id}")
    node1 = api.NodeCreate({"lon": 1, "lat": 1, "tag": {}})
    print(node1)

This code works. For the dev server, one would need to replace OpenStreetMapAuth with OpenStreetMapDevAuth and the api url in the OsmApi initialization.

Maybe at least mention it somewhere in examples? I'm pretty sure the size of the example code currenlty deters people from using this library.

Alternatively it could be added as a dependency and used by default when no session parameter has been passed.

metaodi commented 4 months ago

I don't really want to add it as a dependency (at least for now), but I'm happy to add it as an example to the README and or the examples directory.