Skip to content

Use cli-oauth2 library for OAuth2 #168

@Zverik

Description

@Zverik

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions