Cotter Login SDK for python scripts
Project description
Cotter Login SDK for Python CLI
Cotter's Python SDK for Passwordless Authentication using Email/Phone Number for your CLI and scripts. To read more about Cotter, get started with our 📚 integration guides and example projects.
Find the most updated documentation on our site or our Github:
Installation
pip install cotter
Find the latest versions here https://pypi.org/project/cotter/
Usage
Get your API_KEY_ID from Cotter's Dashboard.
Step 1: Copy cotter_login_success.html from the example folder.
You can make your own Success page. After the user successfully logged-in, the website will redirect to http://localhost:port and you should show a "Success message" and tell the user to go back to your terminal. Feel free to copy our example page and modify it.
Put the success page with name cotter_login_success.html at the same directory as where you put the code below
Step 2: Call Cotter's login function
import cotter
api_key = "YOUR API KEY ID"
port = 8080 # Open a port to receive code from the website after successful authentication
response = cotter.login_with_email_link(api_key, port)
print(response)
Available methods:
Using Email
# Use Magic Link
response = login_with_email_link(api_key, port)
# Use OTP
response = login_with_email_otp(api_key, port)
Using Phone Number
# Use Magic Link
response = login_with_phone_link(api_key, port)
# Use OTP
response = login_with_phone_otp(api_key, port)
Storing the tokens
Store the tokens to a file:
from cotter import tokenhandler
tokenhandler.store_token_to_file(response["oauth_token"], "cottertoken.json")
Get the tokens to a file (automatically refresh if needed):
from cotter import tokenhandler
oauth_token = tokenhandler.get_token_from_file("cottertoken.json", api_key)
Refreshing tokens (if not using the functions above)
# This will only refresh if needed
from cotter import tokenhandler
oauth_token = tokenhandler.refresh_token(oauth_token, api_key)
Validating tokens
from cotter import validate
access_token_decoded = validate.validate_access_token(response["oauth_token"]["access_token"], api_key)
id_token_decoded = validate.validate_id_token(response["oauth_token"]["id_token"], api_key)
Troubleshooting
Allowed Origin Error
If you get an error like this:
{
"msg": "The redirect URL http://localhost:1234 or the parent origin :// is not in the list of allowed URLs. Please contact the site owner.",
"type": ""
}
You may have set up a list of Allowed URLs in the dashboard. Make sure you add these 2 urls:
http://localhost:<PORT>based on the port you used above://(this is a bug, join our Slack channel to be updated)
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
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 cotter-0.0.7.tar.gz.
File metadata
- Download URL: cotter-0.0.7.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fa3d8b500f96ac1a8c5ea734be20e839ca29e461dd28a343dae90205bc5d376
|
|
| MD5 |
9f0d27758679f423887378b0658946c0
|
|
| BLAKE2b-256 |
74ae226a8961964c86b1a2045853d11ffe4873440fe1bd33aa885e25dfdd8dd2
|
File details
Details for the file cotter-0.0.7-py3-none-any.whl.
File metadata
- Download URL: cotter-0.0.7-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
175c26a0f1ace3480e3a31329ec2b569d126d5f72500c7fe496e589cd5e4c2df
|
|
| MD5 |
e435393c87875999166c70fec47510d8
|
|
| BLAKE2b-256 |
57ba9e97afd754947a6fa86b79f1c4d5569409f41129b212a0068fd530225577
|