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:
pip install cotter
Find the latest versions here https://pypi.org/project/cotter/
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
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)
# Use Magic Link
response = login_with_email_link(api_key, port)
# Use OTP
response = login_with_email_otp(api_key, port)
# Use Magic Link
response = login_with_phone_link(api_key, port)
# Use OTP
response = login_with_phone_otp(api_key, port)
from cotter import tokenhandler
tokenhandler.store_token_to_file(response["oauth_token"], "cottertoken.json")
from cotter import tokenhandler
oauth_token = tokenhandler.get_token_from_file("cottertoken.json", api_key)
# This will only refresh if needed
from cotter import tokenhandler
oauth_token = tokenhandler.refresh_token(oauth_token, api_key)
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)
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)