pypale
(Py)thon (Pa)ssword(le)ss Tokens.
pip install pypale
Usage
from pypale import Pypale
token_ttl_minutes = 14 * 24 * 60 # 2 weeks
token_issue_ttl_seconds = 2 * 60 * 60 # 2 hours
base_url = "mydomain.com"
secret_key = "loadthisfromyoursecretsmanager"
pypale = Pypale(
base_url=base_url,
secret_key=secret_key,
token_ttl_minutes=token_ttl_minutes,
token_issue_ttl_seconds=token_issue_ttl_seconds)
email = "jane.doe@example.com"
token = pypale.generate_token(email)
assert pypale.valid_token(token, email)
An example with SendGrid
# send an email with a magic login link to "jane.doe@example.com"
import sendgrid
from sendgrid.helpers.mail import Content, Email, Mail, To
email = "jane.doe@example.com"
token = pypale.generate_token(email)
link = f"https://mydomain.com/link_login/?code={token}"
sg = sendgrid.SendGridAPIClient(api_key=your_sendgrid_api_key)
from_email = Email("bob@mydomain.co")
to_email = To(email)
subject = "Hello!"
content = Content(
"text/html", f"Click this <a href={link}>link</a> to log in.")
mail = Mail(from_email, to_email, subject, content)
response = self.sg.client.mail.send.post(request_body=mail.get())
print (response)
# in your link_login route, mentioned in the link var above,
# make sure to call pypale.validate_token with the token and
# properly handle valid and invalid tokens.
# for example ...
def link_login(code: str):
if not pypale.valid_token(code):
raise Exception("Invalid login.")
access_token = base64.b64decode(code).decode("utf8")
return {
"access_token": base64.b64decode(code).decode("utf8"),
"token_type": "bearer"
}
Contributions & Suggestions
Pull requests and issues are very welcome!
Metadata
Release files for pypale 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypale-0.1.5.tar.gz | 11.3 kB | Without provenance | Details for pypale-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypale-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for pypale-0.1.5-py3-none-any.whl |
Total release size: 15.3 kB
Release files / pypale-0.1.5.tar.gz
| Download URL | pypale-0.1.5.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21d80e4288c04ce1a21923e9a4a1dad969a974e2d9edfce76feadf364719cf2f
|
|
BLAKE2b-256 checksum How to use checksums |
607c83619a9431a29e66382263cab0a3a752b36b10ab6e96880e6fc7604983d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Release files / pypale-0.1.5-py3-none-any.whl
| Download URL | pypale-0.1.5-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5fe8859fda4beba0bb16870434191d8285420338cb6f32f33bcc21018a75cbc1
|
|
BLAKE2b-256 checksum How to use checksums |
d453e5484a2fe46c6340303d35ea4f1e3a88366ed4aca08fe327ae3003849680
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Security for pypale 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.