Skip to main content

Authentication for hayate as a pure fetch(Request) -> Response handler: email+password, sessions, CSRF

Project description

hayate-auth

Standards-first authentication for hayate — a mountable, better-auth-style auth handler built on the WHATWG Request/Response model.

Status: alpha (0.1.x). Email+password, sessions, and CSRF are implemented and attack-regression-tested; email verification and OAuth land in 0.2. Not yet security-audited — see SECURITY.md. The internal design memo (Japanese, per project convention) lives in DESIGN.md.

import os

from hayate import Hayate
from hayate_auth import Auth
from hayate_auth.adapters.sqlite import SQLiteAdapter

adapter = SQLiteAdapter("app.db")
adapter.create_tables()

auth = Auth(secret=os.environ["AUTH_SECRET"], adapter=adapter)

app = Hayate()
auth.register(app)  # serves /api/auth/* (sign-up, sign-in, session, ...)

@app.get("/me", auth.require_session())
async def me(c):
    return c.json(c.get("user"))

The same file runs under any ASGI server and on Cloudflare Python Workers — see examples/todo.

Endpoints (v0.1)

Method / path (under /api/auth) Purpose
POST /sign-up/email Register with email + password, start a session
POST /sign-in/email Verify credentials, start a session
GET /get-session Current {user, session} (or nulls)
POST /sign-out Revoke the session server-side

Why

  • Python has no equivalent of better-auth: a framework-agnostic, self-hosted, schema-owning auth library. django-allauth is Django-only; fastapi-users is in maintenance mode.
  • better-auth works on every JS framework because its core is a single fetch(Request) -> Response handler. hayate is the only Python framework whose user-facing surface is WHATWG Request/Response — so that architecture finally maps 1:1 to Python.
  • Zero-dependency core (its only dependency is hayate, itself zero-dependency). Databases, KDFs, and email are injected protocols.

Security posture

  • Passwords: scrypt at OWASP parameters (N=2^17, r=8, p=1) on every runtime, PBKDF2-HMAC-SHA256 (600k) fallback; PHC-style strings make the backends mutually verifiable. Length-only policy per NIST SP 800-63B.
  • Sessions: opaque 256-bit tokens, only their SHA-256 stored; __Host--prefixed HttpOnly SameSite=Lax cookies on HTTPS.
  • CSRF: SameSite + Origin (RFC 6454) + Fetch Metadata — no token embedding.
  • Sign-in failures are uniform in body and KDF timing (enumeration defense).
  • Coverage ledger: docs/asvs.md (OWASP ASVS V6/V7, ratcheted).
  • You must rate-limit /api/auth/* (hayate middleware or your infrastructure): brute-force throttling is deliberately out of core.

License

MIT

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

hayate_auth-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hayate_auth-0.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file hayate_auth-0.1.0.tar.gz.

File metadata

  • Download URL: hayate_auth-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for hayate_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1fb01ddbc0c5b475fb3bde39afd78abe5449dd0965e5c7c1abc6cac0823e904a
MD5 4cd251fc019be3f5e8d95dc27e06b3ce
BLAKE2b-256 a16f16ce624db296f079c8d8b7c1e5e9e3feb357dc55d85d16ee48fa79937d55

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayate_auth-0.1.0.tar.gz:

Publisher: release.yml on hayatepy/hayate-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hayate_auth-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hayate_auth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for hayate_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e421fc56bdcb694d276d9727066b0c7a01652884e90b5a84fa74e4ac2352c4e6
MD5 bdd9c825aee7568da6214a8e9cb9fe7a
BLAKE2b-256 5eef6be0fb756abb55865335e7c36b21d893ba291335442b544b179bb3e1b9cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayate_auth-0.1.0-py3-none-any.whl:

Publisher: release.yml on hayatepy/hayate-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page