POST /auth/login (form and JSON) now accepts the username in the email field, like HTTP Basic and POST /auth/token always did; the token endpoint no longer lowercases the identifier before the username lookup, fixing mixed-case usernames. The login field is relabelled and type=text so browsers accept a username.
Every JSON return of the personal API key now also returns the account username and email: the profile JSON gains a can_view_api_key-gated email beside api_key (username already rides profile_user), and POST /profile/regenerate-api-key returns {api_key, username, email}. A client holding only its DEVPLACE_API_KEY value can now fetch its full account via GET /profile in one call.
Documented fully: authentication prose page (three credentials, precedence, DEVPLACE_API_KEY, account fetch, separate DevRant/WebSocket auth domains), new auth-token docs_api card, regenerated-key sample, conventions, README, CLAUDE.md, OpenAPI description, corrected profile key hint. Summary in changes.md (left unversioned per request).
Tests: username/mixed-case/uppercase-email login and token cases, API-key account fetch via X-API-KEY and Bearer, owner/admin vs stranger/guest email gating, regenerate shape, browser login by username. Failing-first observed red, green after.
158 lines
4.7 KiB
Python
158 lines
4.7 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import logging
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from devplacepy import errors as error_handlers
|
|
from devplacepy.config import (
|
|
LOG_LEVEL,
|
|
STATIC_DIR,
|
|
STATIC_VERSION,
|
|
UPLOADS_DIR,
|
|
)
|
|
from devplacepy.lifespan import lifespan
|
|
from devplacepy.middleware import register as register_middleware
|
|
from devplacepy.routers import (
|
|
auth,
|
|
battles,
|
|
nodes,
|
|
sync,
|
|
feed,
|
|
posts,
|
|
topics,
|
|
comments,
|
|
projects,
|
|
profile,
|
|
messages,
|
|
notifications,
|
|
votes,
|
|
avatar,
|
|
awards,
|
|
follow,
|
|
relations,
|
|
admin,
|
|
seo,
|
|
issues,
|
|
news,
|
|
gists,
|
|
quizzes,
|
|
uploads,
|
|
giphy,
|
|
media,
|
|
push,
|
|
leaderboard,
|
|
reactions,
|
|
reports,
|
|
bookmarks,
|
|
notes,
|
|
skills,
|
|
polls,
|
|
docs,
|
|
openai_gateway,
|
|
devii,
|
|
zips,
|
|
forks,
|
|
proxy,
|
|
tools,
|
|
xmlrpc,
|
|
devrant,
|
|
dbapi,
|
|
pubsub,
|
|
game,
|
|
workspaces,
|
|
landing,
|
|
)
|
|
from devplacepy.static_files import (
|
|
CachedStaticFiles,
|
|
FallbackStaticFiles,
|
|
UploadStaticFiles,
|
|
)
|
|
|
|
logging.basicConfig(
|
|
level=getattr(logging, LOG_LEVEL, logging.INFO),
|
|
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
)
|
|
logging.getLogger("alembic.runtime.migration").setLevel(logging.WARNING)
|
|
|
|
app = FastAPI(
|
|
title="DevPlace",
|
|
description=(
|
|
"Authentication: username+password, email+password (login form, JSON "
|
|
"POST /auth/login, POST /auth/token, and HTTP Basic all accept the "
|
|
"username or the email address), or the personal API key from the "
|
|
"profile page sent as X-API-KEY or Authorization: Bearer "
|
|
"(conventionally carried in the DEVPLACE_API_KEY environment variable). "
|
|
"GET /profile with an API key returns the account username, email, and "
|
|
"API key. Full reference: /docs/authentication.html"
|
|
),
|
|
docs_url="/swagger",
|
|
redoc_url=None,
|
|
openapi_url="/openapi.json",
|
|
lifespan=lifespan,
|
|
)
|
|
app.mount(
|
|
"/static/uploads",
|
|
UploadStaticFiles(directory=str(UPLOADS_DIR), check_dir=False),
|
|
name="uploads",
|
|
)
|
|
app.mount(
|
|
f"/static/v{STATIC_VERSION}",
|
|
CachedStaticFiles(directory=str(STATIC_DIR)),
|
|
name="static_versioned",
|
|
)
|
|
app.mount("/static", FallbackStaticFiles(directory=str(STATIC_DIR)), name="static")
|
|
|
|
error_handlers.register(app)
|
|
|
|
app.include_router(auth.router, prefix="/auth")
|
|
app.include_router(feed.router, prefix="/feed")
|
|
app.include_router(posts.router, prefix="/posts")
|
|
app.include_router(topics.router, prefix="/topics")
|
|
app.include_router(comments.router, prefix="/comments")
|
|
app.include_router(projects.router, prefix="/projects")
|
|
app.include_router(profile.router, prefix="/profile")
|
|
app.include_router(messages.router, prefix="/messages")
|
|
app.include_router(notifications.router, prefix="/notifications")
|
|
app.include_router(votes.router, prefix="/votes")
|
|
app.include_router(reactions.router, prefix="/reactions")
|
|
app.include_router(reports.router, prefix="/reports")
|
|
app.include_router(bookmarks.router, prefix="/bookmarks")
|
|
app.include_router(notes.router, prefix="/notes")
|
|
app.include_router(skills.router, prefix="/skills")
|
|
app.include_router(polls.router, prefix="/polls")
|
|
app.include_router(avatar.router, prefix="/avatar")
|
|
app.include_router(awards.router, prefix="/awards")
|
|
app.include_router(follow.router, prefix="/follow")
|
|
app.include_router(relations.router)
|
|
app.include_router(leaderboard.router, prefix="/leaderboard")
|
|
app.include_router(admin.router, prefix="/admin")
|
|
app.include_router(seo.router)
|
|
app.include_router(push.router)
|
|
app.include_router(docs.router)
|
|
app.include_router(openai_gateway.router, prefix="/openai")
|
|
app.include_router(devii.router, prefix="/devii")
|
|
app.include_router(issues.router, prefix="/issues")
|
|
app.include_router(gists.router, prefix="/gists")
|
|
app.include_router(news.router, prefix="/news")
|
|
app.include_router(uploads.router, prefix="/uploads")
|
|
app.include_router(giphy.router, prefix="/giphy")
|
|
app.include_router(media.router, prefix="/media")
|
|
app.include_router(zips.router, prefix="/zips")
|
|
app.include_router(forks.router, prefix="/forks")
|
|
app.include_router(proxy.router, prefix="/p")
|
|
app.include_router(tools.router, prefix="/tools")
|
|
app.include_router(xmlrpc.router, prefix="/xmlrpc")
|
|
app.include_router(devrant.router, prefix="/api")
|
|
app.include_router(dbapi.router, prefix="/dbapi")
|
|
app.include_router(pubsub.router, prefix="/pubsub")
|
|
app.include_router(game.router, prefix="/game")
|
|
app.include_router(quizzes.router, prefix="/quizzes")
|
|
app.include_router(battles.router, prefix="/battles")
|
|
app.include_router(nodes.router, prefix="/nodes")
|
|
app.include_router(sync.router, prefix="/sync")
|
|
app.include_router(workspaces.router, prefix="/workspaces")
|
|
app.include_router(landing.router)
|
|
|
|
register_middleware(app)
|