Yep
This commit is contained in:
@@ -15,7 +15,8 @@
|
||||
"Instance": "https://login.microsoftonline.com/",
|
||||
"TenantId": "common",
|
||||
"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": {
|
||||
"AllowedOrigins": [
|
||||
|
||||
@@ -14,11 +14,14 @@ public class Session
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public ShogiBoard Board { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The User.Id of the player which created the session.
|
||||
/// </summary>
|
||||
public string Player1 { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The User.Id of the second player.
|
||||
/// </summary>
|
||||
|
||||
@@ -10,7 +10,6 @@ public class AccountManager
|
||||
{
|
||||
private readonly AccountState accountState;
|
||||
private readonly IShogiApi shogiApi;
|
||||
private readonly IConfiguration configuration;
|
||||
private readonly ILocalStorage localStorage;
|
||||
private readonly AuthenticationStateProvider authState;
|
||||
private readonly NavigationManager navigation;
|
||||
@@ -19,7 +18,6 @@ public class AccountManager
|
||||
public AccountManager(
|
||||
AccountState accountState,
|
||||
IShogiApi unauthenticatedClient,
|
||||
IConfiguration configuration,
|
||||
AuthenticationStateProvider authState,
|
||||
ILocalStorage localStorage,
|
||||
NavigationManager navigation,
|
||||
@@ -27,15 +25,12 @@ public class AccountManager
|
||||
{
|
||||
this.accountState = accountState;
|
||||
this.shogiApi = unauthenticatedClient;
|
||||
this.configuration = configuration;
|
||||
this.authState = authState;
|
||||
this.localStorage = localStorage;
|
||||
this.navigation = navigation;
|
||||
this.shogiSocket = shogiSocket;
|
||||
}
|
||||
|
||||
private User? MyUser => accountState.User;
|
||||
|
||||
private Task SetUser(User user) => accountState.SetUser(user);
|
||||
|
||||
|
||||
|
||||
@@ -3,19 +3,21 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
|
||||
namespace Shogi.UI.Pages.Home.Api
|
||||
{
|
||||
public class MsalMessageHandler : AuthorizationMessageHandler
|
||||
{
|
||||
public MsalMessageHandler(IAccessTokenProvider provider, NavigationManager navigation) : base(provider, navigation)
|
||||
{
|
||||
ConfigureHandler(
|
||||
authorizedUrls: new[] { "https://api.lucaserver.space", "https://localhost:5001" },
|
||||
scopes: new[] { "api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope" },
|
||||
returnUrl: "https://localhost:3000");
|
||||
}
|
||||
public class MsalMessageHandler : AuthorizationMessageHandler
|
||||
{
|
||||
public MsalMessageHandler(IAccessTokenProvider provider, NavigationManager navigation) : base(provider, navigation)
|
||||
{
|
||||
ConfigureHandler(
|
||||
authorizedUrls: new[] { "https://api.lucaserver.space/Shogi.Api", "https://localhost:5001" },
|
||||
scopes: new string[] {
|
||||
"api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope",
|
||||
"offline_access",
|
||||
});
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
|
||||
<div class="pageHeader">
|
||||
<h1>Shogi</h1>
|
||||
@if (user != null)
|
||||
@if (user == null)
|
||||
{
|
||||
<button type="button" class="logout" @onclick="AccountManager.LogoutAsync">Logout</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="user">
|
||||
<div>@user.Value.DisplayName</div>
|
||||
|
||||
@@ -39,7 +39,12 @@ static void ConfigureDependencies(IServiceCollection services, IConfiguration co
|
||||
services.AddMsalAuthentication(options =>
|
||||
{
|
||||
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 =>
|
||||
{
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
}
|
||||
},
|
||||
"AzureAd": {
|
||||
"ClientId": "935df672-efa6-45fa-b2e8-b76dfd65a122",
|
||||
"Authority": "https://login.microsoftonline.com/common",
|
||||
"ClientId": "935df672-efa6-45fa-b2e8-b76dfd65a122",
|
||||
"ValidateAuthority": true,
|
||||
"Scopes": [
|
||||
"profile",
|
||||
"api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -27,6 +27,8 @@ Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "Shogi.Database", "Shogi.Dat
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shogi.Api", "Shogi.Api\Shogi.Api.csproj", "{62604006-6E18-45DA-8D5A-6ADD1C6D3CE2}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "E2ETests", "Tests\E2ETests\E2ETests.csproj", "{401120C3-45D6-4A23-8D87-C2BED29F4950}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -67,6 +73,7 @@ Global
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{4F93F735-DCCE-4A5D-ADDC-E0986DE4C48D} = {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
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1D0B04F2-0DA1-4CB4-A82A-5A1C3B52ACEB}
|
||||
|
||||
23
Tests/E2ETests/E2ETests.csproj
Normal file
23
Tests/E2ETests/E2ETests.csproj
Normal 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>
|
||||
30
Tests/E2ETests/MicrosoftLoginTests.cs
Normal file
30
Tests/E2ETests/MicrosoftLoginTests.cs
Normal 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()
|
||||
}
|
||||
}
|
||||
33
Tests/E2ETests/PlaywriteExample.cs
Normal file
33
Tests/E2ETests/PlaywriteExample.cs
Normal 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
1
Tests/E2ETests/Usings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using NUnit.Framework;
|
||||
3
Tests/E2ETests/appsettings.json
Normal file
3
Tests/E2ETests/appsettings.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user