Metadata-Version: 2.4
Name: tokenly-auth
Version: 1.0.0
Summary: A professional-grade, database-agnostic authentication and session management utility library.
Author-email: err0rgod <nirbhayerror@gmail.com>
License: MIT License
        
        Copyright (c) 2026 err0rgod
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/err0rgod/tokenly
Project-URL: Bug Tracker, https://github.com/err0rgod/tokenly/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Security
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyjwt>=2.8.0
Requires-Dist: argon2-cffi>=23.1.0
Dynamic: license-file

# Tokenly-Auth

Tokenly-Auth is a professional-grade, database-agnostic authentication and session management utility library for Python. It provides high-level security primitives without enforcing any specific database ORM or model structure, giving you total flexibility.

## Core Features

- **Crypto Utilities:** Argon2id password hashing and verification with brute-force protection logic.
- **Token Management:** JWT creation and verification.
- **Session Utilities:** Secure refresh token hashing for rotation strategies.
- **Middleware:** Storage-agnostic rate limiting and authentication decorators.
- **Validation:** Strict structural validation for usernames and passwords.
- **Lightweight:** No dependency on SQLModel, Pydantic, or any specific database driver.

## Installation

```bash
pip install tokenly-auth
```

## Quick Start

### 1. Password Hashing

```python
from tokenly_auth import Security

# Hash a password
hashed = Security["hash"]("my_secure_password")

# Verify a password
is_valid = Security["verify"]("my_secure_password", hashed)

# Reset logic (Verify old -> Hash new)
new_hash = Security["reset"](hashed, "old_password", "new_password")
```

### 2. JWT & Tokens

```python
from tokenly_auth import TokenHandler, SessionManager

handler = TokenHandler(SECRET_KEY="your_secret_key")

# Create Access & Refresh tokens
tokens = handler.createJwt(sub="user_id_123")
# Returns: {"access_token": "...", "refresh_token": "...", "refresh_days": 7}

# Hash refresh token for secure storage
session_util = SessionManager()
storage_hash = session_util.hash_refresh_token(tokens["refresh_token"])
```

### 3. Middleware & Protection

```python
from tokenly_auth import require_auth, TokenHandler

handler = TokenHandler(SECRET_KEY="your_secret_key")

@require_auth(jwt_handler=handler)
def protected_route(payload):
    return f"Hello {payload['sub']}"
```

## Architecture: Why "Database Agnostic"?

Unlike other libraries that force you to use a specific ORM (like SQLAlchemy or SQLModel), Tokenly-Auth acts as a **security toolkit**. 

- **You** control the database (PostgreSQL, MongoDB, Redis, etc.).
- **You** control the models.
- **Tokenly-Auth** handles the heavy lifting of hashing, signing, and security logic.

## Testing

```bash
pytest
```

## License

MIT License.
