- Remove redundant antiforgery check from /_auth/signin and /_auth/signout (JWT validation is sufficient security; antiforgery tokens fail silently because the JS caller never includes one) - Add ILogger structured logging to both endpoints - Make AuthHelper.SignInAsync return bool so Blazor pages can detect failure - Show user-friendly error messages in Login.razor and Register.razor when cookie creation fails
32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using Microsoft.JSInterop;
|
|
|
|
namespace Heimdall.Web.Services;
|
|
|
|
/// <summary>Shared helper for auth-related JS interop calls.</summary>
|
|
internal static class AuthHelper
|
|
{
|
|
/// <summary>Creates the middleware-level auth cookie via JS interop.</summary>
|
|
/// <returns>True if the sign-in HTTP call succeeded (2xx).</returns>
|
|
public static async Task<bool> SignInAsync(IJSRuntime jsRuntime, object user)
|
|
{
|
|
try
|
|
{
|
|
var ok = await jsRuntime.InvokeAsync<bool>("heimdallAuth.signIn", user);
|
|
if (!ok)
|
|
Console.Error.WriteLine("[AuthHelper] SignInAsync: /_auth/signin returned non-2xx status");
|
|
return ok;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine($"[AuthHelper] SignInAsync JS interop failed: {ex.Message}");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates a sign-in payload object with the JWT access token.</summary>
|
|
public static object CreateSignInPayload(string accessToken) => new
|
|
{
|
|
accessToken
|
|
};
|
|
}
|