Include username in auth cookie issuance
This commit is contained in:
@@ -5,6 +5,7 @@ namespace GameList.Infrastructure;
|
||||
public static class PlayerIdentityExtensions
|
||||
{
|
||||
public const string PlayerCookieName = "player";
|
||||
public const string PlayerUsernameCookieName = "player_username";
|
||||
|
||||
public static IApplicationBuilder UsePlayerIdentity(this IApplicationBuilder app)
|
||||
{
|
||||
@@ -28,10 +29,14 @@ public static class PlayerIdentityExtensions
|
||||
return app;
|
||||
}
|
||||
|
||||
public static void IssuePlayerCookie(HttpContext ctx, Guid playerId)
|
||||
public static void IssuePlayerCookie(HttpContext ctx, Guid playerId, string? username = null)
|
||||
{
|
||||
var options = BuildCookieOptions(ctx);
|
||||
ctx.Response.Cookies.Append(PlayerCookieName, playerId.ToString(), options);
|
||||
if (!string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
ctx.Response.Cookies.Append(PlayerUsernameCookieName, username, options);
|
||||
}
|
||||
ctx.Items[PlayerCookieName] = playerId;
|
||||
}
|
||||
|
||||
@@ -40,6 +45,7 @@ public static class PlayerIdentityExtensions
|
||||
var options = BuildCookieOptions(ctx);
|
||||
options.Expires = DateTimeOffset.UtcNow.AddDays(-1);
|
||||
ctx.Response.Cookies.Append(PlayerCookieName, string.Empty, options);
|
||||
ctx.Response.Cookies.Append(PlayerUsernameCookieName, string.Empty, options);
|
||||
ctx.Items.Remove(PlayerCookieName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user