No project description provided
Project description
CT OgWallet Integration Library
Installation
pip install ogwallet-ct-lib
or with poetry:
poetry add ogwallet-ct-lib
Usage
Login
Step 1: Generate login URL and redirect user to it
from ct_lib.og_wallet import OgWallet, GenerateLoginUrlResponse, AuthenticateResponse
base_url = "https://www.example.com/api/v1"
client_id = "client_id"
client_secret = "client_secret"
og_wallet = OgWallet(base_url, client_id, client_secret) # raises error on missing or invalid credentials/URL
# generate login URL
try:
response = og_wallet.generate_login_url("http://crowdtransfer.com/login_callback", ["scope1", "scope2"])
except ValueError as e:
print("Invalid URL or scopes provided!")
except RuntimeError as e:
print("Network error or server responded with non 2xx status code!")
except Exception as e:
print(f"An unexpected error occurred: {e}")
if not isinstance(response, GenerateLoginUrlResponse):
print(f"Failed to generate login URL")
exit(1)
login_url = response["url"]
# redirect user to login_url...
The user now logs in and authorizes the scopes. The user is then redirected back to the callback URL with the auth token.
Step 2: Handle login callback
from django.http import HttpResponse
from ct_lib.og_wallet import OgWallet, GenerateLoginUrlResponse, AuthenticateResponse
og_wallet = OgWallet(base_url, client_id, client_secret)
def og_wallet_login_callback(request):
token = request.GET.get("token")
if not token:
return HttpResponse("Token not found in request", status=400)
try:
response = og_wallet.authenticate(token)
except ValueError as e:
return HttpResponse("Invalid token provided!", status=400)
except RuntimeError as e:
return HttpResponse("Network error or server responded with non 2xx status code!", status=500)
except Exception as e:
return HttpResponse(f"An unexpected error occurred: {e}", status=500)
if not isinstance(response, AuthenticateResponse):
return HttpResponse("Unexpected response from server", status=500)
print(f"User authenticated: {response.id} - {response.email}")
### rest of the code...
Development
Requirements
- Python 3.11
- Poetry
poetry install
Testing
poetry run pytest
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
ogwallet_ct_lib-0.2.0.tar.gz
(2.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ogwallet_ct_lib-0.2.0.tar.gz.
File metadata
- Download URL: ogwallet_ct_lib-0.2.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a1593ad200ed49d8717bafcff686fb432f121015fb41e542082fd86c291e7d5
|
|
| MD5 |
2c419389da0e70b70acbce3ed295657b
|
|
| BLAKE2b-256 |
d0ffca7c21f09b4b1020f0b0fc912938296f759b307dbe7ba242648af4d16542
|
File details
Details for the file ogwallet_ct_lib-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ogwallet_ct_lib-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecc7f2978ad0b27f613c929246381a4de91f67b692907d386d8d6069d79278d3
|
|
| MD5 |
968023d941cddf75ebdc8bb62f3c0e2a
|
|
| BLAKE2b-256 |
00374e64b64c20b5c64f5077dbd4e602bbcc1479c8c34e74f404df0f8ff46dd4
|