From 4c9937f881c8df24d97c8f8f6b8c8e798907635a Mon Sep 17 00:00:00 2001 From: Heimdall Date: Thu, 12 Nov 2026 15:21:40 +0000 Subject: [PATCH] Bifrost: explicit Google link by fresh Heimdall sign-in, no stored token The account page's POST starts an ordinary sign-in whose attempt (a purpose, the expected account id, a pending link id; never a token) is only the proof for a link. Each Heimdall call that needs a bearer follows its own fresh sign-in; the bearer lives in that request. Google stays out of AllowedProviders and member access. Authorization is redacted from HttpClient logging. Outcomes redirect to a fixed closed set of wording. Co-Authored-By: Claude Sonnet 5.5 --- .../Features/Heimdall/HeimdallAuthService.cs | 301 +++++++++++++++++- .../Features/Heimdall/HeimdallCompletePage.cs | 10 +- .../Pages/Membership/Status.cshtml | 13 + .../Pages/Membership/Status.cshtml.cs | 48 ++- src/Bifrost.Web/Program.cs | 30 +- 5 files changed, 380 insertions(+), 22 deletions(-) diff --git a/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs b/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs index 076f788..b24b4ab 100644 --- a/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs +++ b/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs @@ -41,6 +41,14 @@ public sealed class HeimdallAuthService( "twitch" }; + /// Whether a provider may sign a person in (and so be asked for at /auth/heimdall/{provider}). Google is identity only: it can be linked, never signed in with. + public static bool IsSignInProvider(string provider) => AllowedProviders.Contains(provider); + + /// The headers HttpClient logging must never write: the app secret and any bearer. + public static bool RedactsHeader(string header) => + string.Equals(header, AppSecretHeader, StringComparison.OrdinalIgnoreCase) + || string.Equals(header, "Authorization", StringComparison.OrdinalIgnoreCase); + private readonly IDataProtector _protector = dataProtectionProvider.CreateProtector("Bifrost.Heimdall.Attempt.v1"); /// Points the client at Heimdall and, when the app has a secret, identifies Bifrost as the app. @@ -96,7 +104,11 @@ public sealed class HeimdallAuthService( LocalReturnPath returnPath, bool requireMemberAccess, IEnumerable> requestCookies, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + HeimdallAttemptPurpose purpose = HeimdallAttemptPurpose.SignIn, + string? expectedAccountId = null, + string? pendingLinkId = null, + string? replaceSlot = null) { if (!AllowedProviders.Contains(provider)) { @@ -144,11 +156,40 @@ public sealed class HeimdallAuthService( provider, requireMemberAccess, returnPath, - timeProvider.GetUtcNow() + HeimdallAttemptCookie.Lifetime); + timeProvider.GetUtcNow() + HeimdallAttemptCookie.Lifetime, + purpose, + expectedAccountId, + pendingLinkId); return new HeimdallAuthStartResult( - new Uri(payload.AuthorizationUrl, UriKind.Absolute), ChooseSlot(requestCookies), Protect(attempt)); + new Uri(payload.AuthorizationUrl, UriKind.Absolute), replaceSlot ?? ChooseSlot(requestCookies), Protect(attempt)); } + /// The provider a link's fresh sign-in uses: the one the person signed in with, else Discord. + public static string LinkSignInProvider(string? sessionProvider) => + sessionProvider is not null && AllowedProviders.Contains(sessionProvider) ? sessionProvider.ToLowerInvariant() : "discord"; + + /// + /// The account page's link button: an ordinary Heimdall sign-in whose attempt says it is only the proof for a + /// link, and which person it must prove. The session is never replaced by it. + /// + public Task StartLinkAsync( + string sessionAccountId, + string? sessionProvider, + string callbackBaseUrl, + IEnumerable> requestCookies, + CancellationToken cancellationToken) => + StartAsync( + LinkSignInProvider(sessionProvider), + callbackBaseUrl, + LocalReturnPath.Parse(LinkReturnPath), + requireMemberAccess: false, + requestCookies, + cancellationToken, + HeimdallAttemptPurpose.LinkStart, + sessionAccountId); + + public const string LinkReturnPath = "/Membership/Status"; + /// /// The slot the new attempt's cookie takes: the first slot that holds no live attempt, else the one whose /// attempt expires first. Parallel starts carry the same request cookies, so they choose the same slot and @@ -195,15 +236,13 @@ public sealed class HeimdallAuthService( return null; } - public async Task CompleteAsync( - string callbackBaseUrl, - string? nonce, - string? cookieValue, - string? code, - CancellationToken cancellationToken) + /// What the attempt this browser holds for the nonce is for, or null when it holds none. + public HeimdallAttemptPurpose? PurposeOf(string? cookieValue, string? nonce) => Unprotect(cookieValue, nonce)?.Purpose; + + /// Redeems the code of an attempt and verifies the token it carries. The token is returned to the caller's stack frame and nowhere else. + private async Task<(HeimdallVerifiedIdentity Identity, string AccessToken)> RedeemVerifiedAsync( + string callbackBaseUrl, HeimdallAttempt attempt, string? code, CancellationToken cancellationToken) { - var attempt = Unprotect(cookieValue, nonce) - ?? throw new HeimdallAuthException("Heimdall completion has no attempt for this browser."); if (string.IsNullOrWhiteSpace(code)) { throw new HeimdallAuthException("Heimdall completion carried no code."); @@ -221,6 +260,24 @@ public sealed class HeimdallAuthService( } var identity = await tokenVerifier.VerifyAsync(redeemed.AccessToken, redeemed.Account?.Id, cancellationToken); + return (identity, redeemed.AccessToken); + } + + public async Task CompleteAsync( + string callbackBaseUrl, + string? nonce, + string? cookieValue, + string? code, + CancellationToken cancellationToken) + { + var attempt = Unprotect(cookieValue, nonce) + ?? throw new HeimdallAuthException("Heimdall completion has no attempt for this browser."); + if (attempt.Purpose != HeimdallAttemptPurpose.SignIn) + { + throw new HeimdallAuthException("Heimdall completion is not a sign-in attempt."); + } + + var (identity, _) = await RedeemVerifiedAsync(callbackBaseUrl, attempt, code, cancellationToken); if (attempt.RequiresMemberAccess && !identity.HasMemberAccess) { throw new HeimdallAuthException("Heimdall did not grant Bifrost member access."); @@ -236,6 +293,155 @@ public sealed class HeimdallAuthService( attempt.ReturnPath); } + /// + /// One step of a Google link, chosen by the purpose of the attempt this browser holds. The browser's session must be + /// the account the link was begun for, checked before Heimdall is asked anything and again against the identity the + /// fresh sign-in proves. Each step consumes the held attempt: the next step is a new attempt in the same slot, or none. + /// + public async Task ContinueLinkAsync( + string callbackBaseUrl, + string? nonce, + string cookieName, + string? cookieValue, + string? code, + string? pendingLinkId, + string? sessionAccountId, + CancellationToken cancellationToken) + { + var attempt = Unprotect(cookieValue, nonce) + ?? throw new HeimdallAuthException("Heimdall link has no attempt for this browser."); + if (string.IsNullOrEmpty(attempt.ExpectedAccountId) + || !string.Equals(sessionAccountId, attempt.ExpectedAccountId, StringComparison.Ordinal)) + { + throw new HeimdallAuthException("Heimdall link belongs to another session."); + } + + switch (attempt.Purpose) + { + case HeimdallAttemptPurpose.LinkStart: + { + var (_, bearer) = await RedeemOwnerAsync(callbackBaseUrl, attempt, code, cancellationToken); + var authorizationUrl = await StartGoogleLinkAsync(callbackBaseUrl, attempt, bearer, cancellationToken); + return new HeimdallLinkStep(authorizationUrl.Url, cookieName, authorizationUrl.CookieValue, null); + } + + case HeimdallAttemptPurpose.LinkAwaitGoogle: + { + if (string.IsNullOrWhiteSpace(pendingLinkId)) + { + throw new HeimdallAuthException("Heimdall link carried no pending link."); + } + + var next = await StartAsync( + LinkSignInProvider(attempt.Provider), + callbackBaseUrl, + attempt.ReturnPath, + requireMemberAccess: false, + [], + cancellationToken, + HeimdallAttemptPurpose.LinkConfirm, + attempt.ExpectedAccountId, + pendingLinkId, + replaceSlot: cookieName); + return new HeimdallLinkStep(next.AuthorizationUrl, cookieName, next.CookieValue, null); + } + + case HeimdallAttemptPurpose.LinkConfirm: + { + var (identity, bearer) = await RedeemOwnerAsync(callbackBaseUrl, attempt, code, cancellationToken); + var outcome = await ConfirmLinkAsync(attempt.PendingLinkId!, bearer, cancellationToken); + if (outcome == HeimdallLinkOutcome.Linked) + { + // Membership follows the verified identity exactly as at sign-in; the session principal is not replaced. + await UpsertUserAccountAsync(identity, attempt.Provider, grantMemberAccess: false, cancellationToken); + } + + return new HeimdallLinkStep(null, cookieName, null, outcome); + } + + default: + throw new HeimdallAuthException("Heimdall completion is not a link attempt."); + } + } + + /// Redeems a link attempt's code and requires it to prove the account the link was begun for. + private async Task<(HeimdallVerifiedIdentity Identity, string AccessToken)> RedeemOwnerAsync( + string callbackBaseUrl, HeimdallAttempt attempt, string? code, CancellationToken cancellationToken) + { + var proven = await RedeemVerifiedAsync(callbackBaseUrl, attempt, code, cancellationToken); + if (!string.Equals(proven.Identity.AccountId, attempt.ExpectedAccountId, StringComparison.Ordinal)) + { + throw new HeimdallAuthException("Heimdall link was proven by another account."); + } + + return proven; + } + + private async Task<(Uri Url, string CookieValue)> StartGoogleLinkAsync( + string callbackBaseUrl, HeimdallAttempt attempt, string bearer, CancellationToken cancellationToken) + { + var options = heimdallOptions.Value; + var nonce = WebEncoders.Base64UrlEncode(RandomNumberGenerator.GetBytes(32)); + using var message = new HttpRequestMessage(HttpMethod.Post, "/v1/oauth/google/start") + { + Content = JsonContent.Create(new HeimdallStartRequest( + options.AppSlug, "link", ToAttemptReturnUrl(callbackBaseUrl, nonce), new HeimdallHandoff("browser_completion"), null)) + }; + message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", bearer); + using var response = await httpClient.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cancellationToken); + if (!response.IsSuccessStatusCode) + { + throw new HeimdallAuthException(await RefusedStartMessageAsync(response, cancellationToken)); + } + + var payload = await response.Content.ReadFromJsonAsync(cancellationToken); + if (payload is null || string.IsNullOrWhiteSpace(payload.AuthorizationUrl)) + { + throw new HeimdallAuthException("Heimdall link start returned no authorization URL."); + } + + var awaiting = new HeimdallAttempt( + nonce, + attempt.Provider, + false, + attempt.ReturnPath, + timeProvider.GetUtcNow() + HeimdallAttemptCookie.Lifetime, + HeimdallAttemptPurpose.LinkAwaitGoogle, + attempt.ExpectedAccountId, + null); + return (new Uri(payload.AuthorizationUrl, UriKind.Absolute), Protect(awaiting)); + } + + private async Task ConfirmLinkAsync(string pendingLinkId, string bearer, CancellationToken cancellationToken) + { + try + { + using var message = new HttpRequestMessage( + HttpMethod.Post, $"/v1/apps/{Uri.EscapeDataString(heimdallOptions.Value.AppSlug)}/links/confirm") + { + Content = JsonContent.Create(new HeimdallConfirmLinkRequest(pendingLinkId)) + }; + message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", bearer); + using var response = await httpClient.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cancellationToken); + switch (response.StatusCode) + { + case HttpStatusCode.Created: + var linked = await response.Content.ReadFromJsonAsync(cancellationToken); + return linked?.Status == "linked" ? HeimdallLinkOutcome.Linked : HeimdallLinkOutcome.Error; + case HttpStatusCode.Conflict: + return HeimdallLinkOutcome.IdentityLinkedElsewhere; + case HttpStatusCode.Gone: + return HeimdallLinkOutcome.Expired; + default: + return HeimdallLinkOutcome.Error; + } + } + catch (Exception error) when (error is HttpRequestException or JsonException or NotSupportedException && !cancellationToken.IsCancellationRequested) + { + return HeimdallLinkOutcome.Error; + } + } + private async Task RedeemAsync(string code, CancellationToken cancellationToken) { try @@ -260,7 +466,8 @@ public sealed class HeimdallAuthService( private string Protect(HeimdallAttempt attempt) => _protector.Protect(JsonSerializer.Serialize(new AttemptWire( - attempt.Nonce, attempt.Provider, attempt.RequiresMemberAccess, attempt.ReturnPath.Value, attempt.ExpiresAt))); + attempt.Nonce, attempt.Provider, attempt.RequiresMemberAccess, attempt.ReturnPath.Value, attempt.ExpiresAt, + attempt.Purpose, attempt.ExpectedAccountId, attempt.PendingLinkId))); /// The live attempt a cookie value protects when it belongs to this nonce, else null. private HeimdallAttempt? Unprotect(string? cookieValue, string? nonce) => @@ -277,13 +484,14 @@ public sealed class HeimdallAuthService( try { var wire = JsonSerializer.Deserialize(_protector.Unprotect(cookieValue)); - if (wire is null || wire.ExpiresAt <= timeProvider.GetUtcNow()) + if (wire is null || wire.ExpiresAt <= timeProvider.GetUtcNow() || !Enum.IsDefined(wire.Purpose)) { return null; } return new HeimdallAttempt( - wire.Nonce, wire.Provider, wire.RequiresMemberAccess, LocalReturnPath.Parse(wire.ReturnPath), wire.ExpiresAt); + wire.Nonce, wire.Provider, wire.RequiresMemberAccess, LocalReturnPath.Parse(wire.ReturnPath), wire.ExpiresAt, + wire.Purpose, wire.ExpectedAccountId, wire.PendingLinkId); } catch (Exception error) when (error is CryptographicException or JsonException or FormatException) { @@ -296,7 +504,10 @@ public sealed class HeimdallAuthService( string Provider, bool RequiresMemberAccess, string ReturnPath, - DateTimeOffset ExpiresAt); + DateTimeOffset ExpiresAt, + HeimdallAttemptPurpose Purpose = HeimdallAttemptPurpose.SignIn, + string? ExpectedAccountId = null, + string? PendingLinkId = null); private async Task UpsertUserAccountAsync( HeimdallVerifiedIdentity identity, @@ -448,7 +659,65 @@ public sealed record HeimdallAttempt( string Provider, bool RequiresMemberAccess, LocalReturnPath ReturnPath, - DateTimeOffset ExpiresAt); + DateTimeOffset ExpiresAt, + HeimdallAttemptPurpose Purpose = HeimdallAttemptPurpose.SignIn, + string? ExpectedAccountId = null, + string? PendingLinkId = null); + +/// +/// What a held attempt is for. SignIn is the default, so a cookie written before purposes existed reads as a sign-in. +/// The link purposes are the fresh sign-ins and the Google round trip of an explicit link; they never sign anyone in. +/// +public enum HeimdallAttemptPurpose +{ + SignIn = 0, + LinkStart = 1, + LinkAwaitGoogle = 2, + LinkConfirm = 3 +} + +public enum HeimdallLinkOutcome +{ + Linked, + IdentityLinkedElsewhere, + Expired, + Error +} + +/// +/// Where a link step sends the browser: to with a new attempt cookie in the held slot, or, when the +/// link is finished, back to the account page with . +/// +public static class HeimdallLinkOutcomes +{ + public static string Redirect(HeimdallLinkOutcome outcome) => HeimdallAuthService.LinkReturnPath + "?link=" + Code(outcome); + + public static string Code(HeimdallLinkOutcome outcome) => outcome switch + { + HeimdallLinkOutcome.Linked => "linked", + HeimdallLinkOutcome.IdentityLinkedElsewhere => "identity_linked_elsewhere", + HeimdallLinkOutcome.Expired => "expired", + _ => "error" + }; + + /// The words for an outcome code: a closed set, never Heimdall's text. Anything else gets none. + public static string? Wording(string? code) => code switch + { + "linked" => "Google is now linked to your Heimdall account.", + "identity_linked_elsewhere" => "That Google identity is already linked to a different Heimdall account. Nothing was linked.", + "expired" => "The Google link expired before it was confirmed. Nothing was linked; start the link again.", + "error" => "The Google link could not be completed. Nothing was linked.", + _ => null + }; +} + +public sealed record HeimdallLinkStep(Uri? Next, string CookieName, string? CookieValue, HeimdallLinkOutcome? Outcome); + +public sealed record HeimdallConfirmLinkRequest( + [property: JsonPropertyName("pendingLinkId")] string PendingLinkId); + +public sealed record HeimdallConfirmLinkResponse( + [property: JsonPropertyName("status")] string? Status); public sealed record HeimdallStartRequest( [property: JsonPropertyName("appSlug")] string AppSlug, diff --git a/src/Bifrost.Web/Features/Heimdall/HeimdallCompletePage.cs b/src/Bifrost.Web/Features/Heimdall/HeimdallCompletePage.cs index 662fb16..b7d67b2 100644 --- a/src/Bifrost.Web/Features/Heimdall/HeimdallCompletePage.cs +++ b/src/Bifrost.Web/Features/Heimdall/HeimdallCompletePage.cs @@ -3,7 +3,8 @@ namespace Bifrost.Web.Features.Heimdall; /// /// 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. +/// the attempt to the same path. A Google link returns a pending link id the same way instead of a code. The page +/// is static: it never contains a code or an id. /// public static class HeimdallCompletePage { @@ -22,21 +23,24 @@ public static class HeimdallCompletePage
+
diff --git a/src/Bifrost.Web/Pages/Membership/Status.cshtml b/src/Bifrost.Web/Pages/Membership/Status.cshtml index 2c1ab8f..8f683a4 100644 --- a/src/Bifrost.Web/Pages/Membership/Status.cshtml +++ b/src/Bifrost.Web/Pages/Membership/Status.cshtml @@ -24,6 +24,19 @@

@Model.StatusMessage

+ @if (Model.LinkMessage is not null) + { +
@Model.LinkMessage
+ } + + @if (Model.CanLinkGoogle) + { +
+ + You will sign in to Heimdall again, then to Google. Google links your account; it does not sign you in. +
+ } + @if (Model.Invitation is not null) {
diff --git a/src/Bifrost.Web/Pages/Membership/Status.cshtml.cs b/src/Bifrost.Web/Pages/Membership/Status.cshtml.cs index d579dd3..13b47ca 100644 --- a/src/Bifrost.Web/Pages/Membership/Status.cshtml.cs +++ b/src/Bifrost.Web/Pages/Membership/Status.cshtml.cs @@ -1,17 +1,62 @@ using Bifrost.Web.Data; using Bifrost.Web.Domain; +using System.Security.Claims; +using Bifrost.Web.Configuration; +using Bifrost.Web.Features.Heimdall; +using Bifrost.Web.Features.Membership; using Bifrost.Web.Features.Shared; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; namespace Bifrost.Web.Pages.Membership; [Authorize] public sealed class StatusModel( ICurrentBifrostActorAccessor actorAccessor, - BifrostDbContext dbContext) : PageModel + BifrostDbContext dbContext, + HeimdallAuthService heimdallAuthService, + IOptions hostOptions, + ILogger logger) : PageModel { + /// The wording of the link outcome the page was sent back with: a closed set, null for anything else. + public string? LinkMessage { get; private set; } + + /// Whether this session belongs to a Heimdall account a Google login can be attached to. + public bool CanLinkGoogle => User.FindFirstValue(BifrostClaimTypes.HeimdallAccountId) is { Length: > 0 }; + + /// + /// Begins an explicit Google link: an ordinary Heimdall sign-in for the account already signed in here, kept as + /// an attempt that is only the proof for the link. POST with antiforgery only; nothing is started without a session. + /// + public async Task OnPostLinkGoogleAsync(CancellationToken cancellationToken) + { + var accountId = User.FindFirstValue(BifrostClaimTypes.HeimdallAccountId); + if (string.IsNullOrEmpty(accountId)) + { + return RedirectToPage(null, new { link = HeimdallLinkOutcomes.Code(HeimdallLinkOutcome.Error) }); + } + + try + { + var start = await heimdallAuthService.StartLinkAsync( + accountId, + User.FindFirstValue(BifrostClaimTypes.AuthProvider), + hostOptions.Value.PublicBaseUrl, + Request.Cookies, + cancellationToken); + Response.Cookies.Append(start.CookieName, start.CookieValue, HeimdallAttemptCookie.Options()); + return Redirect(start.AuthorizationUrl.ToString()); + } + catch (HeimdallAuthException error) + { + logger.LogWarning("Heimdall link start refused: {Reason}", error.Message); + return RedirectToPage(null, new { link = HeimdallLinkOutcomes.Code(HeimdallLinkOutcome.Error) }); + } + } + public CurrentBifrostActor Actor { get; private set; } = CurrentBifrostActor.Anonymous; public MembershipInvitation? Invitation { get; private set; } @@ -45,6 +90,7 @@ public sealed class StatusModel( public async Task OnGetAsync(CancellationToken cancellationToken) { Actor = await actorAccessor.GetAsync(cancellationToken); + LinkMessage = HeimdallLinkOutcomes.Wording(Request.Query["link"].ToString()); if (Actor.UserAccount is null) { diff --git a/src/Bifrost.Web/Program.cs b/src/Bifrost.Web/Program.cs index be3df54..ef92be8 100644 --- a/src/Bifrost.Web/Program.cs +++ b/src/Bifrost.Web/Program.cs @@ -152,7 +152,7 @@ builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddHttpClient((serviceProvider, client) => HeimdallAuthService.ConfigureClient(client, serviceProvider.GetRequiredService>().Value)) - .RedactLoggedHeaders(header => string.Equals(header, HeimdallAuthService.AppSecretHeader, StringComparison.OrdinalIgnoreCase)); + .RedactLoggedHeaders(HeimdallAuthService.RedactsHeader); builder.Services.AddSingleton(); builder.Services.AddHttpClient(HeimdallTokenVerifier.ClientName, (serviceProvider, client) => HeimdallTokenVerifier.ConfigureClient(client, serviceProvider.GetRequiredService>().Value)); @@ -826,8 +826,32 @@ app.MapPost("/auth/heimdall/complete", async ( var form = await ReadFormOrNullAsync(httpContext.Request, cancellationToken); var attempt = form?["attempt"].ToString(); var held = heimdallAuthService.FindAttemptCookie(httpContext.Request.Cookies, attempt); + var linking = held is not null + && heimdallAuthService.PurposeOf(held.Value.Value, attempt) is not (null or HeimdallAttemptPurpose.SignIn); try { + if (linking) + { + // A link step never signs anyone in: the session in this browser is the one being linked. + var step = await heimdallAuthService.ContinueLinkAsync( + hostOptions.Value.PublicBaseUrl, + attempt, + held!.Value.Name, + held.Value.Value, + form?["code"].ToString(), + form?["pendingLinkId"].ToString(), + httpContext.User.FindFirstValue(BifrostClaimTypes.HeimdallAccountId), + cancellationToken); + if (step.Next is not null) + { + httpContext.Response.Cookies.Append(step.CookieName, step.CookieValue!, HeimdallAttemptCookie.Options()); + return Results.Redirect(step.Next.ToString()); + } + + httpContext.Response.Cookies.Delete(step.CookieName, HeimdallAttemptCookie.DeleteOptions()); + return Results.LocalRedirect(HeimdallLinkOutcomes.Redirect(step.Outcome!.Value)); + } + var signIn = await heimdallAuthService.CompleteAsync( hostOptions.Value.PublicBaseUrl, attempt, @@ -846,7 +870,9 @@ app.MapPost("/auth/heimdall/complete", async ( httpContext.Response.Cookies.Delete(held.Value.Name, HeimdallAttemptCookie.DeleteOptions()); } - return Results.Redirect(HeimdallAuthService.ErrorRedirect); + return linking + ? Results.LocalRedirect(HeimdallLinkOutcomes.Redirect(HeimdallLinkOutcome.Error)) + : Results.Redirect(HeimdallAuthService.ErrorRedirect); } }).AllowAnonymous();