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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user