An authentication system with one-time login links and templated email sending
Project description
OTC Auth System
This OTC Auth system is a Python package that provides a simple authentication mechanism using one-time login links. Users receive an email containing a unique login link, generated by the package, which allows them to authenticate without a password. This package is intended to be integrated into larger projects, providing reusable authentication functionality.
Installation
To install the package, clone the repository or download the source code. Navigate to the root directory of the package and run:
pip install TT_auth_system
This command installs the package and its dependencies.
Setup and Configuration
Environment Variables
The package relies on several environment variables to configure its behavior, particularly for SMTP settings and the base URL of the login link. These should be set in a .env file in the root of the main project using the package.
Create a .env file with the following variables:
SMTP_SERVER: The address of the SMTP server used to send emails (e.g.,smtp.example.com).SMTP_PORT: The port number for the SMTP server (commonly587for TLS or465for SSL).SMTP_USERNAME: The username for SMTP authentication.SMTP_PASSWORD: The password for SMTP authentication.LOGIN_LINK_BASE_URL: The base URL for the login link sent to users. This should point to the part of your application that handles login (e.g.,https://yourapp.com/login).
Example .env file:
SMTP_SERVER=smtp.example.com SMTP_PORT=587 SMTP_USERNAME=your_smtp_username SMTP_PASSWORD=your_smtp_password LOGIN_LINK_BASE_URL=https://yourapp.com/login
HTML Email Template
The package sends an HTML email containing the login link. The HTML template file should be placed in the templates directory at the root of the main project. The file should be named otc_email.html.
Directory Structure: main_project/ ├── .env ├── templates/ │ └── otc_email.html ├── main_script.py └── auth_system/
Example otc_email.html:
Dear user,
Click the link below to log in:
This link is valid for one-time use only.
Best regards,
Your App Team
The {{ login_link }} placeholder will be replaced with the actual login link when the email is sent.
Usage
To use the package in your project, import the necessary functions and configure your environment:
from auth_system import generate_code, send_login_email, store_code, validate_code, purge_valid_codes
Generate a one-time code
code = generate_code()
Send a login email with the generated code
send_login_email("user@example.com", code)
Store the generated code for later validation
store_code(code, "user@example.com")
Validate a code (returns the associated email if valid, None otherwise)
is_valid = validate_code(code)
Purge all valid codes from memory
purge_valid_codes()
Dependencies
The package depends on the following Python libraries:
• python-dotenv: For loading environment variables from a .env file.
• jinja2: For rendering HTML templates.
• smtplib: Part of Python’s standard library, used for sending emails via SMTP.
These dependencies are automatically installed when you install the package using pip.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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
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 TT_auth_system-0.1.0.tar.gz.
File metadata
- Download URL: TT_auth_system-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74341943f787483925bcd92fbda57c31fe30a7b297201da5c12cc8591d03aa62
|
|
| MD5 |
fd51edd49526e911e6cc79fa9843970c
|
|
| BLAKE2b-256 |
72bdd6db838e877e6c9a96c1fd57a7926ac9a94f1575e996c8d642273568ecfe
|
File details
Details for the file TT_auth_system-0.1.0-py3-none-any.whl.
File metadata
- Download URL: TT_auth_system-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
080f4032af39757d8eef13dbbd59e5d04a8409d4986b2b0c02164b74898549ff
|
|
| MD5 |
cd7effafe258d244594e14339f1b5723
|
|
| BLAKE2b-256 |
ef2edf4bb7899e5e3cca3ef9c92cb96c2adfa31e0703dec47e8e46dcaab5ca4b
|