Add username/password auth and login UI
This commit is contained in:
@@ -13,24 +13,14 @@ public static class PlayerIdentityExtensions
|
||||
var pathBase = ctx.Request.PathBase.HasValue ? ctx.Request.PathBase.Value : "/";
|
||||
var isHttps = string.Equals(ctx.Request.Scheme, "https", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
var cookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Secure = isHttps,
|
||||
IsEssential = true,
|
||||
Expires = DateTimeOffset.UtcNow.AddYears(1),
|
||||
Path = pathBase
|
||||
};
|
||||
|
||||
Guid playerId;
|
||||
if (!ctx.Request.Cookies.TryGetValue(PlayerCookieName, out var value) || !Guid.TryParse(value, out playerId))
|
||||
{
|
||||
playerId = Guid.NewGuid();
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.Response.Cookies.Append(PlayerCookieName, playerId.ToString(), cookieOptions);
|
||||
ctx.Items[PlayerCookieName] = playerId;
|
||||
IssuePlayerCookie(ctx, playerId);
|
||||
|
||||
await next();
|
||||
});
|
||||
@@ -38,6 +28,36 @@ public static class PlayerIdentityExtensions
|
||||
return app;
|
||||
}
|
||||
|
||||
public static void IssuePlayerCookie(HttpContext ctx, Guid playerId)
|
||||
{
|
||||
var options = BuildCookieOptions(ctx);
|
||||
ctx.Response.Cookies.Append(PlayerCookieName, playerId.ToString(), options);
|
||||
ctx.Items[PlayerCookieName] = playerId;
|
||||
}
|
||||
|
||||
public static void ClearPlayerCookie(HttpContext ctx)
|
||||
{
|
||||
var options = BuildCookieOptions(ctx);
|
||||
options.Expires = DateTimeOffset.UtcNow.AddDays(-1);
|
||||
ctx.Response.Cookies.Append(PlayerCookieName, string.Empty, options);
|
||||
ctx.Items.Remove(PlayerCookieName);
|
||||
}
|
||||
|
||||
private static CookieOptions BuildCookieOptions(HttpContext ctx)
|
||||
{
|
||||
var pathBase = ctx.Request.PathBase.HasValue ? ctx.Request.PathBase.Value : "/";
|
||||
var isHttps = string.Equals(ctx.Request.Scheme, "https", StringComparison.OrdinalIgnoreCase);
|
||||
return new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Secure = isHttps,
|
||||
IsEssential = true,
|
||||
Expires = DateTimeOffset.UtcNow.AddYears(1),
|
||||
Path = pathBase
|
||||
};
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseGlobalExceptionLogging(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseExceptionHandler(handler =>
|
||||
|
||||
Reference in New Issue
Block a user