Path: redb-identity/tests/redb.Identity.Tests/Infrastructure/LogoutFlow.cs
Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Tests/Infrastructure/LogoutFlow.cs
----
using System.Net;
using System.Text.RegularExpressions;
using AwesomeAssertions;
namespace redb.Identity.Tests.Infrastructure;
///
/// The browser half of a logout without an id_token_hint: /connect/logout answers with a
/// confirmation page whose form carries a state bound to the session, and posting that form back is the
/// confirmation. Tests that sign out by cookie go through here, the way a person clicking the button does.
///
internal static class LogoutFlow
{
private static readonly Regex HiddenInput = new(
"", RegexOptions.Compiled);
public static bool IsConfirmationPage(string html) =>
html.Contains("name=\"logout_state\"", StringComparison.Ordinal);
/// Every hidden field of the confirmation form, HTML-decoded: the state and the relying party's own parameters.
public static Dictionary HiddenFields(string html)
{
var fields = new Dictionary();
foreach (Match m in HiddenInput.Matches(html))
fields[m.Groups[1].Value] = WebUtility.HtmlDecode(m.Groups[2].Value);
return fields;
}
/// Confirms the page in as the same browser and returns the final logout response.
public static async Task ConfirmAsync(HttpClient browser, HttpResponseMessage page)
{
var html = await page.Content.ReadAsStringAsync();
IsConfirmationPage(html).Should().BeTrue(
"a logout by cookie without an id_token_hint answers with the confirmation page first; got {0}: {1}",
(int)page.StatusCode, html.Length > 300 ? html[..300] : html);
return await browser.PostAsync("/connect/logout", new FormUrlEncodedContent(HiddenFields(html)));
}
/// GET with the browser's cookie, then confirm. Returns the final response.
public static async Task SignOutAsync(HttpClient browser, string pathAndQuery = "/connect/logout")
{
var page = await browser.GetAsync(pathAndQuery);
return await ConfirmAsync(browser, page);
}
}