osm-login-python
Package to manage OAuth 2.0 login for OSM in Python.
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:
-
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_uriafter 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).
-
callback() -- Returns the encoded and serialized data:
user_dataa JSON of OSM user data.oauth_tokena string OSM OAuth token.- Both are encoded and serialized as an additional safety measure when used in URLs.
-
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_tokenas 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)
-
Django integration example here https://github.com/hotosm/fAIr/tree/master/backend/login
-
FastAPI integration example here https://github.com/hotosm/raw-data-api/tree/develop/API/auth
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!
Metadata
Release files for osm-login-python 2.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| osm_login_python-2.1.4.tar.gz | 99.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| osm_login_python-2.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 116.8 kB
Release files / osm_login_python-2.1.4.tar.gz
| Download URL | osm_login_python-2.1.4.tar.gz |
|---|---|
| Size | 99.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b07f49d2a70958ac7d8cb043be28017b0b142664a78b718e0cd2ec9344520e8
|
|
BLAKE2b-256 checksum How to use checksums |
16b233a4ffdb17d71946646426658f22df70965193f8ddaf74066ebe7d7f84cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / osm_login_python-2.1.4-py3-none-any.whl
| Download URL | osm_login_python-2.1.4-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
870e85ff22dbaeb2b648d0319c3e3f4ef77fb959ef4a66ba8378ebeaa0834edf
|
|
BLAKE2b-256 checksum How to use checksums |
d55c4cfde6477485604cef14b91c269dd14046a3f25acd7d3530f6f390425907
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for osm-login-python 2.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.