Skip to main content

Package to manage OAuth 2.0 login for OSM in Python.

Project description

osm-login-python

Package to manage OAuth 2.0 login for OSM in Python.

📖 Documentation

pre-commit.ci status

coverage badge

Install with pip

pip install osm-login-python

Import Auth and initialize class with your credentials

from osm_login_python.core import Auth
osm_auth=Auth(
    osm_url=YOUR_OSM_URL,
    client_id=YOUR_OSM_CLIENT_ID,
    client_secret=YOUR_OSM_CLIENT_SECRET,
    secret_key=YOUR_OSM_SECRET_KEY,
    login_redirect_uri=YOUR_OSM_LOGIN_REDIRECT_URI,
    scope=YOUR_OSM_SCOPE_LIST,
)

Usage

Three functions are provided:

  1. login() -- Returns the login url for OSM.

    • The user must then access this URL and authorize the OAuth application to login.
    • The user will be redirected to the configured login_redirect_uri after successful login with OSM.
    • The web page must then call the callback() function below, sending the current URL to the function (which includes the OAuth authorization code).
  2. callback() -- Returns the encoded and serialized data:

    • user_data a JSON of OSM user data.
    • oauth_token a string OSM OAuth token.
    • Both are encoded and serialized as an additional safety measure when used in URLs.
  3. deserialize_data() -- returns decoded and deserialized data from callback().

[!NOTE] This package is primarily intended to return OSM user data.

It is also possible to obtain the oauth_token as described above, for making authenticated requests against the OSM API from within a secure backend service.

To use the OAuth token in a frontend please use caution and adhere to best practice security, such as embedding in a secure httpOnly cookie (do not store in localStorage, sessionStorage, or unsecure cookies).

Example

In Django:

import json
from django.conf import settings
from osm_login_python.core import Auth
from django.http import JsonResponse

# initialize osm_auth with our credentials
osm_auth = Auth(
    osm_url=YOUR_OSM_URL,
    client_id=YOUR_OSM_CLIENT_ID,
    client_secret=YOUR_OSM_CLIENT_SECRET,
    secret_key=YOUR_OSM_SECRET_KEY,
    login_redirect_uri=YOUR_OSM_LOGIN_REDIRECT_URI,
    scope=YOUR_OSM_SCOPE,
)

def login(request):
    login_url = osm_auth.login()
    return JsonResponse(login_url)

def callback(request):
    # Generating token through osm_auth library method
    token = osm_auth.callback(request.build_absolute_uri())
    return JsonResponse(token)

def get_my_data(request, serialized_user_data: str):
    user_data = osm_auth.deserialize_data(serialized_user_data)
    return JsonResponse(user_data)

Version Control

Use commitizen for version control.

Test Coverage

Generate a coverage badge:

uv sync --extra test
uv run coverage run -m pytest
# uv run coverage report
uv run coverage-badge -o docs/coverage.svg

Contribute

Contributions are welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osm_login_python-2.1.1.tar.gz (86.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osm_login_python-2.1.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file osm_login_python-2.1.1.tar.gz.

File metadata

  • Download URL: osm_login_python-2.1.1.tar.gz
  • Upload date:
  • Size: 86.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for osm_login_python-2.1.1.tar.gz
Algorithm Hash digest
SHA256 622692691b81e515956d882f6c2ff53e32b24800f8727ec57e4fbc4482308a8a
MD5 853bdae5b9f4db8913a97f0bafe9988b
BLAKE2b-256 9df0bb9ec7a4a8093938053a97e0bb7f8bb742508f3a427010d06bb6f279fc23

See more details on using hashes here.

File details

Details for the file osm_login_python-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: osm_login_python-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for osm_login_python-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a642647b4e814f90153c4f49be2e5650ef8341b38d57ae76d8181e5843f80ad
MD5 f02fec441327fbbf7895cae30db9751c
BLAKE2b-256 62832459f532dc9d0e159feaddd85715684ff67fa3e5f0263a3b8f1a691fda73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page