fix: Callback bestätigt direkt statt Weiterleitung (Sitzung gehört danach dem technischen Konto)

Claude-Session: https://claude.ai/code/session_01SqzF6qT3TQ8ej3wigEuMSu
This commit is contained in:
Rsclub2_2 committed 2026-10-29 15:23:51 +01:00
1 parent 7ee574b9dd
commit 8afecd553c
3 files changed
+41 -5

No files matched your search

+11 -3
View File
@@ -150,14 +150,22 @@ def oidc_callback():
if not OAUTH:
abort(404)
if request.args.get("error"):
return redirect(url_for("index", error=request.args["error"]))
return render_template("index.html", email_address=EMAIL_USERNAME, oauth=True, connected=False,
error=request.args["error"]), 400
try:
OAUTH.finish(request.args.get("state", ""), request.args.get("code", ""))
except OAuthError as e:
logger.warning("Mailbox connect failed: %s", e)
return redirect(url_for("index", error=str(e)))
return render_template("index.html", email_address=EMAIL_USERNAME, oauth=True, connected=False,
error=str(e)), 400
logger.info("Collection mailbox %s connected via OAuth", EMAIL_USERNAME)
return redirect(url_for("index"))
# the browser session now belongs to the technical account, which forward_auth does not let in:
# confirm here instead of redirecting to the start page
return (
"<!doctype html><meta charset=utf-8><title>Connected</title>"
"<p>Collection mailbox connected. Close this private window and open the Unsubscriber again "
"in your normal browser.</p>"
)
@app.route("/disconnect", methods=["POST"])
+3 -2
View File
@@ -19,8 +19,9 @@
</form>
{% endif %}
{% else %}
<p>The collection mailbox is not connected yet. Open this page in a private window and sign in
as <strong>{{ email_address }}</strong> (technical account) – not with your own account.</p>
<p>The collection mailbox is not connected yet. In a private window: open this page, sign in with
<strong>your own account</strong>, click “Connect mailbox”, then sign in as
<strong>{{ email_address }}</strong> (technical account).</p>
<form action="/connect" method="get">
<button type="submit" class="btn-primary">Connect mailbox</button>
</form>
+27
View File
@@ -139,3 +139,30 @@ def test_index_shows_connect_when_not_connected(monkeypatch):
monkeypatch.setattr(unsub, "OAUTH", FakeOAuth())
html = unsub.app.test_client().get("/").get_data(as_text=True)
assert 'action="/connect"' in html and 'action="/result"' not in html
def test_callback_confirms_without_redirect(monkeypatch):
import app as unsub
class FakeOAuth:
def finish(self, state, code):
assert (state, code) == ("s", "c")
monkeypatch.setattr(unsub, "OAUTH", FakeOAuth())
r = unsub.app.test_client().get("/oidc/callback?state=s&code=c")
assert r.status_code == 200 and "connected" in r.get_data(as_text=True)
def test_callback_error_is_shown(monkeypatch):
import app as unsub
class FakeOAuth:
def finish(self, state, code):
raise oauth.OAuthError("Signed in as philipp@example.org, expected unsubscribe-bot@example.org")
def connected(self):
return False
monkeypatch.setattr(unsub, "OAUTH", FakeOAuth())
r = unsub.app.test_client().get("/oidc/callback?state=s&code=c")
assert r.status_code == 400 and "expected unsubscribe-bot" in r.get_data(as_text=True)