Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53e662d

Browse files
authored
Preserve RemoteAuthenticationContext during JS interop (#54225) (#54655)
1 parent7869bfc commit53e662d

File tree

18 files changed

+354
-5
lines changed

18 files changed

+354
-5
lines changed

‎AspNetCore.sln‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Output
17821782
EndProject
17831783
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotReferencedInWasmCodePackage", "src\Components\test\testassets\NotReferencedInWasmCodePackage\NotReferencedInWasmCodePackage.csproj", "{433F91E4-E39D-4EB0-B798-2998B3969A2C}"
17841784
EndProject
1785+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components.WasmRemoteAuthentication", "src\Components\test\testassets\Components.WasmRemoteAuthentication\Components.WasmRemoteAuthentication.csproj", "{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}"
1786+
EndProject
17851787
Global
17861788
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17871789
Debug|Any CPU = Debug|Any CPU
@@ -10735,6 +10737,22 @@ Global
1073510737
{433F91E4-E39D-4EB0-B798-2998B3969A2C}.Release|x64.Build.0 = Release|Any CPU
1073610738
{433F91E4-E39D-4EB0-B798-2998B3969A2C}.Release|x86.ActiveCfg = Release|Any CPU
1073710739
{433F91E4-E39D-4EB0-B798-2998B3969A2C}.Release|x86.Build.0 = Release|Any CPU
10740+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10741+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|Any CPU.Build.0 = Debug|Any CPU
10742+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|arm64.ActiveCfg = Debug|Any CPU
10743+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|arm64.Build.0 = Debug|Any CPU
10744+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x64.ActiveCfg = Debug|Any CPU
10745+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x64.Build.0 = Debug|Any CPU
10746+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x86.ActiveCfg = Debug|Any CPU
10747+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x86.Build.0 = Debug|Any CPU
10748+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|Any CPU.ActiveCfg = Release|Any CPU
10749+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|Any CPU.Build.0 = Release|Any CPU
10750+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|arm64.ActiveCfg = Release|Any CPU
10751+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|arm64.Build.0 = Release|Any CPU
10752+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x64.ActiveCfg = Release|Any CPU
10753+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x64.Build.0 = Release|Any CPU
10754+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x86.ActiveCfg = Release|Any CPU
10755+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x86.Build.0 = Release|Any CPU
1073810756
EndGlobalSection
1073910757
GlobalSection(SolutionProperties) = preSolution
1074010758
HideSolutionNode = FALSE
@@ -11615,6 +11633,7 @@ Global
1161511633
{A939893A-B3CD-48F6-80D3-340C8A6E275B} = {AA5ABFBC-177C-421E-B743-005E0FD1248B}
1161611634
{F232B503-D412-45EE-8B31-EFD46B9FA302} = {AA5ABFBC-177C-421E-B743-005E0FD1248B}
1161711635
{433F91E4-E39D-4EB0-B798-2998B3969A2C} = {6126DCE4-9692-4EE2-B240-C65743572995}
11636+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13} = {6126DCE4-9692-4EE2-B240-C65743572995}
1161811637
EndGlobalSection
1161911638
GlobalSection(ExtensibilityGlobals) = postSolution
1162011639
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

‎src/Components/Components.slnf‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"src\\Components\\test\\testassets\\BasicTestApp\\BasicTestApp.csproj",
5353
"src\\Components\\test\\testassets\\Components.TestServer\\Components.TestServer.csproj",
5454
"src\\Components\\test\\testassets\\Components.WasmMinimal\\Components.WasmMinimal.csproj",
55+
"src\\Components\\test\\testassets\\Components.WasmRemoteAuthentication\\Components.WasmRemoteAuthentication.csproj",
5556
"src\\Components\\test\\testassets\\ComponentsApp.App\\ComponentsApp.App.csproj",
5657
"src\\Components\\test\\testassets\\ComponentsApp.Server\\ComponentsApp.Server.csproj",
5758
"src\\Components\\test\\testassets\\GlobalizationWasmApp\\GlobalizationWasmApp.csproj",

‎src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
108108
RemoteAuthenticationContext<TRemoteAuthenticationState>context)
109109
{
110110
awaitEnsureAuthService();
111-
varresult=awaitJsRuntime.InvokeAsync<RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signIn",context);
111+
varresult=awaitJSInvokeWithContextAsync<RemoteAuthenticationContext<TRemoteAuthenticationState>,RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signIn",context);
112112
awaitUpdateUserOnSuccess(result);
113113

114114
returnresult;
@@ -130,7 +130,7 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
130130
RemoteAuthenticationContext<TRemoteAuthenticationState>context)
131131
{
132132
awaitEnsureAuthService();
133-
varresult=awaitJsRuntime.InvokeAsync<RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signOut",context);
133+
varresult=awaitJSInvokeWithContextAsync<RemoteAuthenticationContext<TRemoteAuthenticationState>,RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signOut",context);
134134
awaitUpdateUserOnSuccess(result);
135135

136136
returnresult;
@@ -187,6 +187,11 @@ public virtual async ValueTask<AccessTokenResult> RequestAccessToken(AccessToken
187187
}:null);
188188
}
189189

190+
// JSRuntime.InvokeAsync does not properly annotate all arguments with DynamicallyAccessedMembersAttribute. https://github.com/dotnet/aspnetcore/issues/39839
191+
// Calling JsRuntime.InvokeAsync directly results allows the RemoteAuthenticationContext.State getter to be trimmed. https://github.com/dotnet/aspnetcore/issues/49956
192+
privateValueTask<TResult>JSInvokeWithContextAsync<[DynamicallyAccessedMembers(JsonSerialized)]TContext,[DynamicallyAccessedMembers(JsonSerialized)]TResult>(
193+
stringidentifier,TContextcontext)=>JsRuntime.InvokeAsync<TResult>(identifier,context);
194+
190195
privatestringGetReturnUrl(string?customReturnUrl)=>
191196
customReturnUrl!=null?Navigation.ToAbsoluteUri(customReturnUrl).AbsoluteUri:Navigation.Uri;
192197

‎src/Components/test/E2ETest/Infrastructure/ServerFixtures/AspNetSiteServerFixture.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override IHost CreateWebHost()
3232
}
3333

3434
varassembly=ApplicationAssembly??BuildWebHostMethod.Method.DeclaringType.Assembly;
35-
varsampleSitePath=DefaultGetContentRoot(assembly);
35+
varsampleSitePath=GetContentRootMethod(assembly);
3636

3737
varhost="127.0.0.1";
3838
if(E2ETestOptions.Instance.SauceTest)

‎src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ProjectSdk="Microsoft.NET.Sdk">
1+
<ProjectSdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<!--
44
Skip building and running the Components E2E tests in CI unless explicitly configured otherwise via
@@ -85,6 +85,11 @@
8585
Include="..\..\WebAssembly\testassets\Wasm.Prerendered.Server\Wasm.Prerendered.Server.csproj"
8686
Targets="Build;Publish"
8787
Properties="BuildProjectReferences=false;TestTrimmedApps=true;PublishDir=$(MSBuildThisFileDirectory)$(OutputPath)trimmed\Wasm.Prerendered.Server\;" />
88+
89+
<ProjectReference
90+
Include="..\testassets\Components.TestServer\Components.TestServer.csproj"
91+
Targets="Build;Publish"
92+
Properties="BuildProjectReferences=false;TestTrimmedOrMultithreadingApps=true;PublishDir=$(MSBuildThisFileDirectory)$(OutputPath)trimmed-or-threading\Components.TestServer\;" />
8893
</ItemGroup>
8994

9095
<!-- Shared testing infrastructure for running E2E tests using selenium-->
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
usingSystem.Reflection;
5+
usingMicrosoft.AspNetCore.Components.E2ETest.Infrastructure;
6+
usingMicrosoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
usingMicrosoft.AspNetCore.E2ETesting;
8+
usingMicrosoft.AspNetCore.Hosting;
9+
usingMicrosoft.Extensions.DependencyInjection;
10+
usingMicrosoft.Extensions.Hosting;
11+
usingMicrosoft.Extensions.Logging;
12+
usingMicrosoft.Extensions.Logging.Testing;
13+
usingOpenQA.Selenium;
14+
usingTestServer;
15+
usingXunit.Abstractions;
16+
17+
namespaceMicrosoft.AspNetCore.Components.E2ETest.Tests;
18+
19+
publicclassRemoteAuthenticationTest:
20+
ServerTestBase<BasicTestAppServerSiteFixture<RemoteAuthenticationStartup>>
21+
{
22+
publicreadonlyboolTestTrimmedApps=typeof(ToggleExecutionModeServerFixture<>).Assembly
23+
.GetCustomAttributes<AssemblyMetadataAttribute>()
24+
.First(m=>m.Key=="Microsoft.AspNetCore.E2ETesting.TestTrimmedOrMultithreadingApps")
25+
.Value=="true";
26+
27+
publicRemoteAuthenticationTest(
28+
BrowserFixturebrowserFixture,
29+
BasicTestAppServerSiteFixture<RemoteAuthenticationStartup>serverFixture,
30+
ITestOutputHelperoutput)
31+
:base(browserFixture,serverFixture,output)
32+
{
33+
serverFixture.ApplicationAssembly=typeof(RemoteAuthenticationStartup).Assembly;
34+
35+
if(TestTrimmedApps)
36+
{
37+
serverFixture.BuildWebHostMethod=BuildPublishedWebHost;
38+
serverFixture.GetContentRootMethod=GetPublishedContentRoot;
39+
}
40+
}
41+
42+
[Fact]
43+
publicvoidNavigateToLogin_PreservesExtraQueryParams()
44+
{
45+
// If the preservedExtraQueryParams passed to NavigateToLogin by RedirectToLogin gets trimmed,
46+
// the OIDC endpoints will fail to authenticate the user.
47+
Navigate("/subdir/test-remote-authentication");
48+
49+
varheading=Browser.Exists(By.TagName("h1"));
50+
Browser.Equal("Hello, Jane Doe!",()=>heading.Text);
51+
}
52+
53+
privatestaticIHostBuildPublishedWebHost(string[]args)=>
54+
Host.CreateDefaultBuilder(args)
55+
.ConfigureLogging((ctx,lb)=>
56+
{
57+
TestSinksink=newTestSink();
58+
lb.AddProvider(newTestLoggerProvider(sink));
59+
lb.Services.AddSingleton(sink);
60+
})
61+
.ConfigureWebHostDefaults(webHostBuilder=>
62+
{
63+
webHostBuilder.UseStartup<RemoteAuthenticationStartup>();
64+
// Avoid UseStaticAssets or we won't use the trimmed published output.
65+
})
66+
.Build();
67+
68+
privatestaticstringGetPublishedContentRoot(Assemblyassembly)
69+
{
70+
varcontentRoot=Path.Combine(AppContext.BaseDirectory,"trimmed-or-threading",assembly.GetName().Name);
71+
72+
if(!Directory.Exists(contentRoot))
73+
{
74+
thrownewDirectoryNotFoundException($"Test is configured to use trimmed outputs, but trimmed outputs were not found in{contentRoot}.");
75+
}
76+
77+
returncontentRoot;
78+
}
79+
}

‎src/Components/test/E2ETest/Tests/WebAssemblyPrerenderedTest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void WaitUntilLoaded()
5656

5757
privatestaticstringGetPublishedContentRoot(Assemblyassembly)
5858
{
59-
varcontentRoot=Path.Combine(AppContext.BaseDirectory,"trimmed",assembly.GetName().Name);
59+
varcontentRoot=Path.Combine(AppContext.BaseDirectory,"trimmed-or-threading",assembly.GetName().Name);
6060

6161
if(!Directory.Exists(contentRoot))
6262
{

‎src/Components/test/testassets/Components.TestServer/Components.TestServer.csproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
<ReferenceInclude="Microsoft.AspNetCore.SignalR" />
2626
<ReferenceInclude="Microsoft.AspNetCore.Testing" />
2727
<ReferenceInclude="Microsoft.Extensions.Hosting" />
28+
<ReferenceInclude="Microsoft.IdentityModel.Protocols.OpenIdConnect" />
2829
</ItemGroup>
2930

3031
<ItemGroup>
3132
<ProjectReferenceInclude="..\BasicTestApp\BasicTestApp.csproj" />
3233
<ProjectReferenceInclude="..\Components.WasmMinimal\Components.WasmMinimal.csproj" />
34+
<ProjectReferenceInclude="..\Components.WasmRemoteAuthentication\Components.WasmRemoteAuthentication.csproj" />
3335
</ItemGroup>
3436

3537
<ItemGroup>

‎src/Components/test/testassets/Components.TestServer/Program.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static async Task Main(string[] args)
1919
varcreateIndividualHosts=newDictionary<string,(IHosthost,stringbasePath)>
2020
{
2121
["Client authentication"]=(BuildWebHost<AuthenticationStartup>(CreateAdditionalArgs(args)),"/subdir"),
22+
["Remote client authentication"]=(BuildWebHost<RemoteAuthenticationStartup>(CreateAdditionalArgs(args)),"/subdir"),
2223
["Server authentication"]=(BuildWebHost<ServerAuthenticationStartup>(CreateAdditionalArgs(args)),"/subdir"),
2324
["CORS (WASM)"]=(BuildWebHost<CorsStartup>(CreateAdditionalArgs(args)),"/subdir"),
2425
["Prerendering (Server-side)"]=(BuildWebHost<PrerenderedStartup>(CreateAdditionalArgs(args)),"/prerendered"),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<htmllang="en">
3+
4+
<head>
5+
<metacharset="utf-8" />
6+
<basehref="/subdir/" />
7+
8+
<HeadOutlet@rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
9+
</head>
10+
11+
<body>
12+
<Components.WasmRemoteAuthentication.Routes@rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
13+
<scriptsrc="_framework/blazor.web.js"autostart="false"></script>
14+
<scriptsrc="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
15+
<script>
16+
Blazor.start({
17+
webAssembly: {
18+
loadBootResource: (type,name,defaultUri,integrity)=>`WasmRemoteAuthentication/_framework/${name}`
19+
}
20+
});
21+
</script>
22+
</body>
23+
24+
</html>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp