Fix claims.
Use OID instead of email for microsoft identifier. Fix PlayerCount route. Add created date to user table. Create spectator icon.
This commit is contained in:
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Shogi.UI.Pages.Home.Api;
|
||||
using Shogi.UI.Shared;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Shogi.UI.Pages.Home.Account;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class AccountManager
|
||||
|
||||
public async Task LoginWithGuestAccount()
|
||||
{
|
||||
var response = await shogiApi.GetToken();
|
||||
var response = await shogiApi.GetToken(WhichAccountPlatform.Guest);
|
||||
if (response != null)
|
||||
{
|
||||
MyUser = new User
|
||||
@@ -56,7 +57,7 @@ public class AccountManager
|
||||
public async Task LoginWithMicrosoftAccount()
|
||||
{
|
||||
var state = await authState.GetAuthenticationStateAsync();
|
||||
|
||||
|
||||
if (state.User?.Identity?.Name == null || state.User?.Identity?.IsAuthenticated == false)
|
||||
{
|
||||
// Set the login platform so that we know to log in with microsoft after being redirected away from the UI.
|
||||
@@ -64,21 +65,6 @@ public class AccountManager
|
||||
navigation.NavigateToLogin("authentication/login");
|
||||
return;
|
||||
}
|
||||
|
||||
//var response = await shogiApi.GetToken();
|
||||
//if (response != null)
|
||||
//{
|
||||
// MyUser = new User
|
||||
// {
|
||||
// DisplayName = response.DisplayName,
|
||||
// Id = response.UserId,
|
||||
// OneTimeSocketToken = response.OneTimeToken,
|
||||
// WhichAccountPlatform = WhichAccountPlatform.Microsoft,
|
||||
// };
|
||||
|
||||
// await shogiSocket.OpenAsync(MyUser.Value.OneTimeSocketToken.ToString());
|
||||
// await localStorage.SetAccountPlatform(WhichAccountPlatform.Microsoft);
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,16 +77,14 @@ public class AccountManager
|
||||
Console.WriteLine($"Try Login Silent - {platform}");
|
||||
if (platform == WhichAccountPlatform.Guest)
|
||||
{
|
||||
var response = await shogiApi.GetToken();
|
||||
var response = await shogiApi.GetToken(WhichAccountPlatform.Guest);
|
||||
if (response != null)
|
||||
{
|
||||
MyUser = new User
|
||||
{
|
||||
DisplayName = response.DisplayName,
|
||||
Id = response.UserId,
|
||||
OneTimeSocketToken = response.OneTimeToken,
|
||||
WhichAccountPlatform = WhichAccountPlatform.Guest
|
||||
};
|
||||
MyUser = new User(
|
||||
Id: response.UserId,
|
||||
DisplayName: response.DisplayName,
|
||||
WhichAccountPlatform: WhichAccountPlatform.Guest,
|
||||
OneTimeSocketToken: response.OneTimeToken);
|
||||
}
|
||||
}
|
||||
else if (platform == WhichAccountPlatform.Microsoft)
|
||||
@@ -108,20 +92,20 @@ public class AccountManager
|
||||
var state = await authState.GetAuthenticationStateAsync();
|
||||
if (state.User?.Identity?.Name != null)
|
||||
{
|
||||
var response = await shogiApi.GetToken();
|
||||
var response = await shogiApi.GetToken(WhichAccountPlatform.Microsoft);
|
||||
if (response == null)
|
||||
{
|
||||
// Login failed, so reset local storage to avoid putting the user in a broken state.
|
||||
await localStorage.DeleteAccountPlatform();
|
||||
return false;
|
||||
}
|
||||
var id = state.User.Identity;
|
||||
MyUser = new User
|
||||
{
|
||||
DisplayName = id.Name,
|
||||
Id = id.Name,
|
||||
OneTimeSocketToken = response.OneTimeToken
|
||||
};
|
||||
var id = state.User.Claims.Single(claim => claim.Type == "oid").Value;
|
||||
var displayName = state.User.Identity.Name;
|
||||
MyUser = new User(
|
||||
Id: id,
|
||||
DisplayName: displayName,
|
||||
WhichAccountPlatform: WhichAccountPlatform.Microsoft,
|
||||
OneTimeSocketToken: response.OneTimeToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,11 +123,12 @@ public class AccountManager
|
||||
MyUser = null;
|
||||
var platform = await localStorage.GetAccountPlatform();
|
||||
await localStorage.DeleteAccountPlatform();
|
||||
|
||||
|
||||
if (platform == WhichAccountPlatform.Guest)
|
||||
{
|
||||
await shogiApi.GuestLogout();
|
||||
} else if (platform == WhichAccountPlatform.Microsoft)
|
||||
}
|
||||
else if (platform == WhichAccountPlatform.Microsoft)
|
||||
{
|
||||
navigation.NavigateToLogout("authentication/logout");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Shogi.Contracts.Api;
|
||||
using Shogi.Contracts.Types;
|
||||
using Shogi.UI.Pages.Home.Account;
|
||||
using System.Net;
|
||||
|
||||
namespace Shogi.UI.Pages.Home.Api;
|
||||
@@ -8,7 +9,7 @@ public interface IShogiApi
|
||||
{
|
||||
Task<Session?> GetSession(string name);
|
||||
Task<ReadSessionsPlayerCountResponse?> GetSessionsPlayerCount();
|
||||
Task<CreateTokenResponse?> GetToken();
|
||||
Task<CreateTokenResponse?> GetToken(WhichAccountPlatform whichAccountPlatform);
|
||||
Task GuestLogout();
|
||||
Task Move(string sessionName, MovePieceCommand move);
|
||||
Task<HttpStatusCode> PostSession(string name, bool isPrivate);
|
||||
|
||||
@@ -57,10 +57,12 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<CreateTokenResponse?> GetToken()
|
||||
public async Task<CreateTokenResponse?> GetToken(WhichAccountPlatform whichAccountPlatform)
|
||||
{
|
||||
Console.WriteLine($"GetToken() - {accountState.User?.WhichAccountPlatform}");
|
||||
var response = await HttpClient.GetFromJsonAsync<CreateTokenResponse>(new Uri("User/Token", UriKind.Relative), serializerOptions);
|
||||
var httpClient = whichAccountPlatform == WhichAccountPlatform.Microsoft
|
||||
? clientFactory.CreateClient(MsalClientName)
|
||||
: clientFactory.CreateClient(GuestClientName);
|
||||
var response = await httpClient.GetFromJsonAsync<CreateTokenResponse>(new Uri("User/Token", UriKind.Relative), serializerOptions);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,16 @@
|
||||
@inject PromotePrompt PromotePrompt;
|
||||
|
||||
<article class="game-board">
|
||||
@if (IsSpectating)
|
||||
{
|
||||
<aside class="icons">
|
||||
<div class="spectating" title="You are spectating.">
|
||||
<svg width="32" height="32" fill="currentColor">
|
||||
<use xlink:href="css/bootstrap/bootstrap-icons.svg#camera-reels" />
|
||||
</svg>
|
||||
</div>
|
||||
</aside>
|
||||
}
|
||||
<!-- Game board -->
|
||||
<section class="board" data-perspective="@Perspective">
|
||||
@for (var rank = 1; rank < 10; rank++)
|
||||
@@ -79,6 +89,7 @@
|
||||
</article>
|
||||
|
||||
@code {
|
||||
[Parameter] public bool IsSpectating { get; set; } = false;
|
||||
[Parameter] public WhichPlayer Perspective { get; set; }
|
||||
[Parameter] public Session? Session { get; set; }
|
||||
[Parameter] public string? SelectedPosition { get; set; }
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
.game-board {
|
||||
display: grid;
|
||||
grid-template-areas: "board side-board";
|
||||
grid-template-columns: 3fr minmax(10rem, 1fr);
|
||||
grid-template-areas: "board side-board icons";
|
||||
grid-template-columns: 3fr minmax(10rem, 1fr) auto;
|
||||
gap: 0.5rem;
|
||||
background-color: #444;
|
||||
position: relative; /* For absolute positioned children. */
|
||||
}
|
||||
|
||||
.board {
|
||||
@@ -13,6 +14,9 @@
|
||||
.side-board {
|
||||
grid-area: side-board;
|
||||
}
|
||||
.icons {
|
||||
grid-area: icons;
|
||||
}
|
||||
|
||||
.board {
|
||||
position: relative;
|
||||
@@ -110,3 +114,11 @@
|
||||
.promote-prompt[data-visible="true"] {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.spectating {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
color: var(--contrast-color)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
@using Contracts.Types;
|
||||
|
||||
<p>You are spectating</p>
|
||||
<GameBoardPresentation Perspective="WhichPlayer.Player1" Session="Session" />
|
||||
<GameBoardPresentation IsSpectating="true" Perspective="WhichPlayer.Player1" Session="Session" />
|
||||
|
||||
@code {
|
||||
[Parameter] public Session Session { get; set; }
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
.shogi > ::deep .game-board {
|
||||
grid-area: board;
|
||||
place-self: center;
|
||||
place-self: center start;
|
||||
}
|
||||
|
||||
.shogi > ::deep .pageHeader {
|
||||
|
||||
Reference in New Issue
Block a user