massive checkpoint

This commit is contained in:
2021-09-03 22:43:06 -05:00
parent bb1d2c491c
commit 2a3b7b32b4
40 changed files with 456 additions and 738 deletions

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using System.Net.WebSockets;
@@ -30,5 +31,7 @@ namespace Gameboard.ShogiUI.Sockets.Models
{
Player2 = userName;
}
public Game ToServiceModel() => new() { GameName = Name, Player1 = Player1, Player2 = Player2 };
}
}

View File

@@ -10,7 +10,7 @@
public string? Player2 { get; private set; }
public bool IsPrivate { get; }
public SessionMetadata(string name, bool isPrivate, string player1, string? player2)
public SessionMetadata(string name, bool isPrivate, string player1, string? player2 = null)
{
Name = name;
IsPrivate = isPrivate;

View File

@@ -1,18 +1,57 @@
using System;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using System;
using System.Collections.Generic;
using System.Security.Claims;
namespace Gameboard.ShogiUI.Sockets.Models
{
public class User
{
public static readonly string GuestPrefix = "Guest-";
public string Name { get; }
public Guid? WebSessionId { get; }
public bool IsGuest => Name.StartsWith(GuestPrefix) && WebSessionId.HasValue;
public User(string name, Guid? webSessionId = null)
public bool IsGuest => WebSessionId.HasValue;
public User(string name)
{
Name = name;
}
/// <summary>
/// Constructor for guest user.
/// </summary>
public User(string name, Guid webSessionId)
{
Name = name;
WebSessionId = webSessionId;
}
public ClaimsIdentity CreateMsalUserIdentity()
{
var claims = new List<Claim>()
{
new Claim(ClaimTypes.NameIdentifier, Name),
new Claim(ClaimTypes.Role, "Shogi") // The Shogi role grants access to api controllers.
};
return new ClaimsIdentity(claims, JwtBearerDefaults.AuthenticationScheme);
}
public ClaimsIdentity CreateGuestUserIdentity()
{
// TODO: Make this method static and factory-like.
if (!WebSessionId.HasValue)
{
throw new InvalidOperationException("Cannot create guest identity without a session identifier.");
}
var claims = new List<Claim>()
{
new Claim(ClaimTypes.NameIdentifier, WebSessionId.Value.ToString()),
new Claim(ClaimTypes.Role, "Guest"),
new Claim(ClaimTypes.Role, "Shogi") // The Shogi role grants access to api controllers.
};
return new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
}
}
}

View File

@@ -0,0 +1,8 @@
namespace Gameboard.ShogiUI.Sockets.Models
{
public enum WhichLoginPlatform
{
Microsoft,
Guest
}
}