massive checkpoint
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
Gameboard.ShogiUI.Sockets/Models/WhichLoginPlatform.cs
Normal file
8
Gameboard.ShogiUI.Sockets/Models/WhichLoginPlatform.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public enum WhichLoginPlatform
|
||||
{
|
||||
Microsoft,
|
||||
Guest
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user