Start puts a per-attempt nonce in the returnTo it sends Heimdall and keeps the attempt (provider, member flag, local return path, expiry) in a Data Protection cookie named for that nonce. Heimdall's completion page sends the browser to /auth/heimdall/complete with a code in the URL fragment; the page posts it back, Bifrost redeems it at Heimdall, requires the redeemed returnTo to name the cookie's nonce, verifies the access token for the redeemed account, and signs that browser in. Deleted: the callback route, the wait route, the server-side attempt store, the pending state and the backend_callback handoff. Added: LocalReturnPath for return targets, Heimdall:AppSecret sent as x-heimdall-app-secret (member starts are refused without it), a short timeout on the key fetch, and a key lookup that does not hold the fetch gate for cached keys. Refusals at the completion route all answer one redirect and log a fixed reason. Tests are rewritten against a fake Heimdall with start and redeem routes. Not compile-checked by this commit alone; later commits record the verification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.9 KiB
C#
46 lines
1.9 KiB
C#
namespace Bifrost.Web.Features.Heimdall;
|
|
|
|
/// <summary>
|
|
/// The page Heimdall's "Return to the app" lands on. The completion code arrives in the URL fragment, which
|
|
/// the server never sees, so the page's script reads it, drops it from the address bar, and posts it with
|
|
/// the attempt to the same path. The page is static: it never contains a code.
|
|
/// </summary>
|
|
public static class HeimdallCompletePage
|
|
{
|
|
public const string Html = """
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<meta name="referrer" content="no-referrer" />
|
|
<title>Signing in - Bifrost</title>
|
|
</head>
|
|
<body>
|
|
<p>Finishing sign-in...</p>
|
|
<noscript><p>JavaScript is needed to finish sign-in.</p></noscript>
|
|
<form id="complete" method="post" action="/auth/heimdall/complete">
|
|
<input type="hidden" name="attempt" />
|
|
<input type="hidden" name="code" />
|
|
</form>
|
|
<script>
|
|
(function () {
|
|
var fragment = new URLSearchParams(location.hash.slice(1));
|
|
var attempt = new URLSearchParams(location.search).get("attempt");
|
|
var code = fragment.get("heimdall_completion_code");
|
|
var failed = fragment.get("heimdall_status") === "error";
|
|
history.replaceState(null, "", location.pathname + location.search);
|
|
if (failed || !code || !attempt) {
|
|
location.replace("/?auth=heimdall-error");
|
|
return;
|
|
}
|
|
var form = document.getElementById("complete");
|
|
form.elements.attempt.value = attempt;
|
|
form.elements.code.value = code;
|
|
form.submit();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
""";
|
|
}
|