Metadata-Version: 2.1
Name: osm-login-python
Version: 1.0.3
Summary: Use OSM Token exchange with OAuth2.0 for python projects.
License: GPL-3.0-only
Keywords: osm,openstreetmap,oauth2,login,hot
Author-email: Kshitij Raj Sharma <skshitizraj@gmail.com>
Requires-Python: >=3.9
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Utilities
Requires-Dist: itsdangerous>=2.0.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: requests-oauthlib>=1.3.0
Provides-Extra: docs
Requires-Dist: mkdocs>=1.5.3; extra == "docs"
Requires-Dist: mkdocs-material>=9.4.2; extra == "docs"
Requires-Dist: mkdocstrings-python>=1.7.0; extra == "docs"
Requires-Dist: mkdocs-exclude>=1.0.2; extra == "docs"
Provides-Extra: test
Requires-Dist: pytest>=7.4.2; extra == "test"
Project-URL: documentation, https://hotosm.github.io/osm-login-python
Project-URL: homepage, https://hotosm.github.io/osm-login-python
Project-URL: repository, https://github.com/hotosm/osm-login-python
Description-Content-Type: text/markdown

# 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

📖 [Documentation](https://hotosm.github.io/osm-login-python/)

## Install with [pip](https://pypi.org/project/osm-login-python/)

```bash
pip install osm-login-python
```

## Import Auth and initialize class with your credentials

```python
from osm_login_python.core import Auth
```

```python
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 :

1. login() -- Returns the login url for osm
2. callback() -- Returns the access token for the user
3. deserialize_access_token() -- returns the user data

## Example

On django :

```python
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=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,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](https://pypi.org/project/commitizen/) for version control

### Contirbute

Contributions are welcome !

