Use OSM Token exchange with OAuth2.0 for python projects.
Project description
osm-login-python
Library to provide osm login oauth2.0 exchange to python projects
Makes it very easier to implement osm authentication login to their project with oauth2.0
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)
Usage
Provides 3 Functions inside Auth class :
- login() -- Returns the login url for osm
- callback() -- Returns the access token for the user
- deserialize_access_token() -- returns the user data
Example
On django :
from django.conf import settings
from osm_login_python.core import Auth
from django.http import JsonResponse
import json
# initialize osm_auth with our credentials
osm_auth=Auth(osm_url=settings.OSM_URL, client_id=settings.OSM_CLIENT_ID,client_secret=settings.OSM_CLIENT_SECRET, secret_key=settings.OSM_SECRET_KEY, login_redirect_uri=settings.OSM_LOGIN_REDIRECT_URI, scope=settings.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,access_token: str):
user_data=osm_auth.deserialize_access_token(access_token)
return JsonResponse(user_data)
-
Check Django integration example here https://github.com/hotosm/fAIr/tree/master/backend/login
-
Check FastAPI integration example here https://github.com/hotosm/export-tool-api/tree/develop/API/auth
Version Control
Use commitizen for version control
Contirbute
Contributions are welcome !
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file osm-login-python-1.0.1.tar.gz
.
File metadata
- Download URL: osm-login-python-1.0.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.8.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d00e6318e22d7c363ddb552a62397351ad15bb1090e3d21ddde7a1de466343a8 |
|
MD5 | a2b12d0a9ded9675061b25b8434a9664 |
|
BLAKE2b-256 | 96dfbc4ce62d284930c39b37fe5b80ba70baa6719a9e64fa41550bd1bb32cc1f |
File details
Details for the file osm_login_python-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: osm_login_python-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.8.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e69200b6d1e97f46337643a030e093dde7490ba11b5a85598e74630cde601d0 |
|
MD5 | 81e908f3254182100c13f1a166d0b2dd |
|
BLAKE2b-256 | 8dff5d3a2d833d34267913a9e973edde24134ae04717995c63487a7add79cb13 |