init_app should fail fast on missing SECRET_KEY and unresolvable campus.auth origin

Open
#44 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
flask, python

Research direction

Start in login_manager.py at OAuthLoginManager.init_app, where the session provider and request hook are installed. Read how app.secret_key is accessed and how get_base_url resolves the campus.auth origin; add the proposed boot checks there and run the existing test suite. Done means missing configuration fails during initialization with a useful error, while configured apps and TESTING environments initialize successfully.

Written by the indexing model from the issue text.

Description

enhancement

flask_campus's login flow depends on two environment facts that currently
surface only at first use, so each consumer app reimplements boot-time
checks locally.

  1. SECRET_KEY — OAuthLoginManager.init_app installs the session
    provider and the login flow writes flask.session (login_next, OAuth
    state). Unset, Flask accepts the app until the session is first used and
    dies far from the cause. Worked example: nyjc-computing/campus-profile#60,
    implemented per-app in PR nyjc-computing/campus-profile#64 (closed
    unmerged in favour of this issue).
  2. campus.auth origin — the before_request hook re-resolves the
    campus.auth origin on every request, so a missing
    CAMPUS_AUTH_URL/CAMPUS_BASE_URL/BASE_URL 500s every page, landing
    included. Worked example: nyjc-computing/campus-profile#59, implemented
    per-app in PR nyjc-computing/campus-profile#66 (closed unmerged in favour
    of this issue).

Proposal: enforce in OAuthLoginManager.init_app — the natural
integration point, since it already installs the session provider and
registers the request hook:

  • Guard app.secret_key (Flask instances only; blueprints have none) and
    raise with a message naming the variable and a generation snippet
    (python -c 'import secrets; print(secrets.token_urlsafe())').
  • Eagerly resolve the campus.auth origin once via
    campus.common.services.resolve_base_url("campus.auth") — the module is
    already imported in login_manager.py (get_base_url), so this is
    dependency-clean. The resolver's error message is already good
    ("set CAMPUS_AUTH_URL, or CAMPUS_BASE_URL / BASE_URL for a gateway
    origin"); resolving at init turns per-request 500s into one loud boot
    failure. campus-common's TESTING short-circuit keeps test environments
    green.

Layering note: keep it narrow — each layer fails fast on what it itself
consumes. campus-common keeps owning resolution semantics; campus_python
already fails at import for its own credentials; app-specific env (e.g.
PUBLIC_URL) stays the app's job. No generic env-schema validator.

Deployment semantics: raising at import is what actually blocks a
Railway deploy — the process dies, the deploy goes red, the old release
keeps serving.

Migration: consumers delete their local boot checks and pin the next
flask-campus release. campus-profile's local implementations (PRs #64/#66
above) are the reference behaviour.

Dominant language
Python
Stars
0
Forks
0
Avg merge
9m
Merged PRs (30d)
40

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nyjc-computing/flask-campus

All issues in nyjc-computing/flask-campus

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.