Fixes critical IndieAuth authentication failure by implementing modern JSON-based client discovery mechanism per IndieAuth spec section 4.2. Added /.well-known/oauth-authorization-server endpoint returning JSON metadata with client_id, redirect_uris, and OAuth capabilities. Added <link rel="indieauth-metadata"> discovery hint in HTML head. Maintained h-app microformats for backward compatibility with legacy IndieAuth servers. This resolves "client_id is not registered" error from IndieLogin.com by providing the metadata document modern IndieAuth servers expect. Changes: - Added oauth_client_metadata() endpoint in public routes - Returns JSON with client info (24-hour cache) - Uses config values (SITE_URL, SITE_NAME) not hardcoded URLs - Added indieauth-metadata link in base.html - Comprehensive test suite (15 new tests, all passing) - Updated version to v0.6.2 (PATCH increment) - Updated CHANGELOG.md with detailed fix documentation Standards Compliance: - IndieAuth specification section 4.2 - OAuth Client ID Metadata Document format - IANA well-known URI registry - RFC 7591 OAuth 2.0 Dynamic Client Registration Testing: - 467/468 tests passing (99.79%) - 15 new tests for OAuth metadata and discovery - Zero regressions in existing tests - Test coverage maintained at 88% Related Documentation: - ADR-017: OAuth Client ID Metadata Document Implementation - IndieAuth Fix Summary report - Implementation report in docs/reports/ Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
110 lines
2.9 KiB
Python
110 lines
2.9 KiB
Python
"""
|
|
StarPunk package initialization
|
|
Creates and configures the Flask application
|
|
"""
|
|
|
|
from flask import Flask
|
|
|
|
|
|
def create_app(config=None):
|
|
"""
|
|
Application factory for StarPunk
|
|
|
|
Args:
|
|
config: Optional configuration dict to override defaults
|
|
|
|
Returns:
|
|
Configured Flask application instance
|
|
"""
|
|
app = Flask(__name__, static_folder="../static", template_folder="../templates")
|
|
|
|
# Load configuration
|
|
from starpunk.config import load_config
|
|
|
|
load_config(app, config)
|
|
|
|
# Initialize database
|
|
from starpunk.database import init_db
|
|
|
|
init_db(app)
|
|
|
|
# Register blueprints
|
|
from starpunk.routes import register_routes
|
|
|
|
register_routes(app)
|
|
|
|
# Error handlers
|
|
@app.errorhandler(404)
|
|
def not_found(error):
|
|
from flask import render_template, request
|
|
|
|
# Return HTML for browser requests, JSON for API requests
|
|
if request.path.startswith("/api/"):
|
|
return {"error": "Not found"}, 404
|
|
return render_template("404.html"), 404
|
|
|
|
@app.errorhandler(500)
|
|
def server_error(error):
|
|
from flask import render_template, request
|
|
|
|
# Return HTML for browser requests, JSON for API requests
|
|
if request.path.startswith("/api/"):
|
|
return {"error": "Internal server error"}, 500
|
|
return render_template("500.html"), 500
|
|
|
|
# Health check endpoint for containers and monitoring
|
|
@app.route("/health")
|
|
def health_check():
|
|
"""
|
|
Health check endpoint for containers and monitoring
|
|
|
|
Returns:
|
|
JSON with status and basic info
|
|
|
|
Response codes:
|
|
200: Application healthy
|
|
500: Application unhealthy
|
|
|
|
Checks:
|
|
- Database connectivity
|
|
- File system access
|
|
- Basic application state
|
|
"""
|
|
from flask import jsonify
|
|
import os
|
|
|
|
try:
|
|
# Check database connectivity
|
|
from starpunk.database import get_db
|
|
|
|
db = get_db(app)
|
|
db.execute("SELECT 1").fetchone()
|
|
db.close()
|
|
|
|
# Check filesystem access
|
|
data_path = app.config.get("DATA_PATH", "data")
|
|
if not os.path.exists(data_path):
|
|
raise Exception("Data path not accessible")
|
|
|
|
return (
|
|
jsonify(
|
|
{
|
|
"status": "healthy",
|
|
"version": app.config.get("VERSION", __version__),
|
|
"environment": app.config.get("ENV", "unknown"),
|
|
}
|
|
),
|
|
200,
|
|
)
|
|
|
|
except Exception as e:
|
|
return jsonify({"status": "unhealthy", "error": str(e)}), 500
|
|
|
|
return app
|
|
|
|
|
|
# Package version (Semantic Versioning 2.0.0)
|
|
# See docs/standards/versioning-strategy.md for details
|
|
__version__ = "0.6.2"
|
|
__version_info__ = (0, 6, 2)
|