This commit is contained in:
2023-05-14 18:55:19 -05:00
parent 257504fa72
commit 809ca92c8a
13 changed files with 130 additions and 24 deletions

View File

@@ -15,7 +15,8 @@
"Instance": "https://login.microsoftonline.com/", "Instance": "https://login.microsoftonline.com/",
"TenantId": "common", "TenantId": "common",
"ClientId": "c1e94676-cab0-42ba-8b6c-9532b8486fff", "ClientId": "c1e94676-cab0-42ba-8b6c-9532b8486fff",
"SwaggerUIClientId": "26bf69a4-2af8-4711-bf5b-79f75e20b082" "SwaggerUIClientId": "26bf69a4-2af8-4711-bf5b-79f75e20b082",
"Scope": "api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope"
}, },
"Cors": { "Cors": {
"AllowedOrigins": [ "AllowedOrigins": [

View File

@@ -14,11 +14,14 @@ public class Session
} }
public string Name { get; } public string Name { get; }
public ShogiBoard Board { get; } public ShogiBoard Board { get; }
/// <summary> /// <summary>
/// The User.Id of the player which created the session. /// The User.Id of the player which created the session.
/// </summary> /// </summary>
public string Player1 { get; } public string Player1 { get; }
/// <summary> /// <summary>
/// The User.Id of the second player. /// The User.Id of the second player.
/// </summary> /// </summary>

View File

@@ -10,7 +10,6 @@ public class AccountManager
{ {
private readonly AccountState accountState; private readonly AccountState accountState;
private readonly IShogiApi shogiApi; private readonly IShogiApi shogiApi;
private readonly IConfiguration configuration;
private readonly ILocalStorage localStorage; private readonly ILocalStorage localStorage;
private readonly AuthenticationStateProvider authState; private readonly AuthenticationStateProvider authState;
private readonly NavigationManager navigation; private readonly NavigationManager navigation;
@@ -19,7 +18,6 @@ public class AccountManager
public AccountManager( public AccountManager(
AccountState accountState, AccountState accountState,
IShogiApi unauthenticatedClient, IShogiApi unauthenticatedClient,
IConfiguration configuration,
AuthenticationStateProvider authState, AuthenticationStateProvider authState,
ILocalStorage localStorage, ILocalStorage localStorage,
NavigationManager navigation, NavigationManager navigation,
@@ -27,15 +25,12 @@ public class AccountManager
{ {
this.accountState = accountState; this.accountState = accountState;
this.shogiApi = unauthenticatedClient; this.shogiApi = unauthenticatedClient;
this.configuration = configuration;
this.authState = authState; this.authState = authState;
this.localStorage = localStorage; this.localStorage = localStorage;
this.navigation = navigation; this.navigation = navigation;
this.shogiSocket = shogiSocket; this.shogiSocket = shogiSocket;
} }
private User? MyUser => accountState.User;
private Task SetUser(User user) => accountState.SetUser(user); private Task SetUser(User user) => accountState.SetUser(user);

View File

@@ -8,9 +8,11 @@ namespace Shogi.UI.Pages.Home.Api
public MsalMessageHandler(IAccessTokenProvider provider, NavigationManager navigation) : base(provider, navigation) public MsalMessageHandler(IAccessTokenProvider provider, NavigationManager navigation) : base(provider, navigation)
{ {
ConfigureHandler( ConfigureHandler(
authorizedUrls: new[] { "https://api.lucaserver.space", "https://localhost:5001" }, authorizedUrls: new[] { "https://api.lucaserver.space/Shogi.Api", "https://localhost:5001" },
scopes: new[] { "api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope" }, scopes: new string[] {
returnUrl: "https://localhost:3000"); "api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope",
"offline_access",
});
} }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

View File

@@ -3,7 +3,11 @@
<div class="pageHeader"> <div class="pageHeader">
<h1>Shogi</h1> <h1>Shogi</h1>
@if (user != null) @if (user == null)
{
<button type="button" class="logout" @onclick="AccountManager.LogoutAsync">Logout</button>
}
else
{ {
<div class="user"> <div class="user">
<div>@user.Value.DisplayName</div> <div>@user.Value.DisplayName</div>

View File

@@ -39,7 +39,12 @@ static void ConfigureDependencies(IServiceCollection services, IConfiguration co
services.AddMsalAuthentication(options => services.AddMsalAuthentication(options =>
{ {
configuration.Bind("AzureAd", options.ProviderOptions.Authentication); configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
options.ProviderOptions.LoginMode = "redirect"; //options.ProviderOptions.DefaultAccessTokenScopes.Add("https://graph.microsoft.com/User.Read");
//options.ProviderOptions.DefaultAccessTokenScopes.Add("openid");
//options.ProviderOptions.DefaultAccessTokenScopes.Add("offline_access");
//options.ProviderOptions.DefaultAccessTokenScopes.Add("profile");
//options.ProviderOptions.LoginMode = "redirect";
}); });
services.AddOidcAuthentication(options => services.AddOidcAuthentication(options =>
{ {

View File

@@ -5,11 +5,10 @@
} }
}, },
"AzureAd": { "AzureAd": {
"ClientId": "935df672-efa6-45fa-b2e8-b76dfd65a122",
"Authority": "https://login.microsoftonline.com/common", "Authority": "https://login.microsoftonline.com/common",
"ClientId": "935df672-efa6-45fa-b2e8-b76dfd65a122",
"ValidateAuthority": true, "ValidateAuthority": true,
"Scopes": [ "Scopes": [
"profile",
"api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope" "api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope"
] ]
}, },

View File

@@ -27,6 +27,8 @@ Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "Shogi.Database", "Shogi.Dat
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shogi.Api", "Shogi.Api\Shogi.Api.csproj", "{62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shogi.Api", "Shogi.Api\Shogi.Api.csproj", "{62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "E2ETests", "Tests\E2ETests\E2ETests.csproj", "{401120C3-45D6-4A23-8D87-C2BED29F4950}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -60,6 +62,10 @@ Global
{62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}.Debug|Any CPU.Build.0 = Debug|Any CPU {62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}.Release|Any CPU.ActiveCfg = Release|Any CPU {62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}.Release|Any CPU.Build.0 = Release|Any CPU {62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}.Release|Any CPU.Build.0 = Release|Any CPU
{401120C3-45D6-4A23-8D87-C2BED29F4950}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{401120C3-45D6-4A23-8D87-C2BED29F4950}.Debug|Any CPU.Build.0 = Debug|Any CPU
{401120C3-45D6-4A23-8D87-C2BED29F4950}.Release|Any CPU.ActiveCfg = Release|Any CPU
{401120C3-45D6-4A23-8D87-C2BED29F4950}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -67,6 +73,7 @@ Global
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{4F93F735-DCCE-4A5D-ADDC-E0986DE4C48D} = {A968C8E6-47B7-4F72-A27A-AC9B643FD320} {4F93F735-DCCE-4A5D-ADDC-E0986DE4C48D} = {A968C8E6-47B7-4F72-A27A-AC9B643FD320}
{30F4E3DB-027F-4885-BE06-884167C1C6CF} = {A968C8E6-47B7-4F72-A27A-AC9B643FD320} {30F4E3DB-027F-4885-BE06-884167C1C6CF} = {A968C8E6-47B7-4F72-A27A-AC9B643FD320}
{401120C3-45D6-4A23-8D87-C2BED29F4950} = {A968C8E6-47B7-4F72-A27A-AC9B643FD320}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D0B04F2-0DA1-4CB4-A82A-5A1C3B52ACEB} SolutionGuid = {1D0B04F2-0DA1-4CB4-A82A-5A1C3B52ACEB}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.30.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,30 @@
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace E2ETests;
[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class MicrosoftLoginTests : PageTest
{
[SetUp]
public async void Init()
{
}
[Test]
public async Task Test1()
{
await Page.GotoAsync("https://lucaserver.space/shogi", new PageGotoOptions { WaitUntil = WaitUntilState.NetworkIdle });
var loginButton = Page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Log in" });
await loginButton.ClickAsync();
//await Page.WaitForURLAsync()
}
}

View File

@@ -0,0 +1,33 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
namespace E2ETests;
[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class PlaywriteExample : PageTest
{
[Test]
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");
// Expect a title "to contain" a substring.
await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
// create a locator
var getStarted = Page.GetByRole(AriaRole.Link, new() { Name = "Get started" });
// Expect an attribute "to be strictly equal" to the value.
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro");
// Click the get started link.
await getStarted.ClickAsync();
// Expects the URL to contain intro.
await Expect(Page).ToHaveURLAsync(new Regex(".*intro"));
}
}

1
Tests/E2ETests/Usings.cs Normal file
View File

@@ -0,0 +1 @@
global using NUnit.Framework;

View File

@@ -0,0 +1,3 @@
{
}