Skip to content

Commit 85e61c5

Browse files
committed
Add trimmed E2E RemoteAuthenticationTest
1 parent 1d59a11 commit 85e61c5

17 files changed

+368
-5
lines changed

AspNetCore.sln

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Intern
17861786
EndProject
17871787
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotReferencedInWasmCodePackage", "src\Components\test\testassets\NotReferencedInWasmCodePackage\NotReferencedInWasmCodePackage.csproj", "{433F91E4-E39D-4EB0-B798-2998B3969A2C}"
17881788
EndProject
1789+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components.WasmRemoteAuth", "src\Components\test\testassets\Components.WasmRemoteAuth\Components.WasmRemoteAuth.csproj", "{D2848C1B-4962-4B94-AC5F-A3C368C5B351}"
1790+
EndProject
1791+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components.WasmRemoteAuthentication", "src\Components\test\testassets\Components.WasmRemoteAuthentication\Components.WasmRemoteAuthentication.csproj", "{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}"
1792+
EndProject
17891793
Global
17901794
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17911795
Debug|Any CPU = Debug|Any CPU
@@ -10771,6 +10775,38 @@ Global
1077110775
{433F91E4-E39D-4EB0-B798-2998B3969A2C}.Release|x64.Build.0 = Release|Any CPU
1077210776
{433F91E4-E39D-4EB0-B798-2998B3969A2C}.Release|x86.ActiveCfg = Release|Any CPU
1077310777
{433F91E4-E39D-4EB0-B798-2998B3969A2C}.Release|x86.Build.0 = Release|Any CPU
10778+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10779+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|Any CPU.Build.0 = Debug|Any CPU
10780+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|arm64.ActiveCfg = Debug|Any CPU
10781+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|arm64.Build.0 = Debug|Any CPU
10782+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|x64.ActiveCfg = Debug|Any CPU
10783+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|x64.Build.0 = Debug|Any CPU
10784+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|x86.ActiveCfg = Debug|Any CPU
10785+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Debug|x86.Build.0 = Debug|Any CPU
10786+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|Any CPU.ActiveCfg = Release|Any CPU
10787+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|Any CPU.Build.0 = Release|Any CPU
10788+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|arm64.ActiveCfg = Release|Any CPU
10789+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|arm64.Build.0 = Release|Any CPU
10790+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|x64.ActiveCfg = Release|Any CPU
10791+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|x64.Build.0 = Release|Any CPU
10792+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|x86.ActiveCfg = Release|Any CPU
10793+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351}.Release|x86.Build.0 = Release|Any CPU
10794+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10795+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|Any CPU.Build.0 = Debug|Any CPU
10796+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|arm64.ActiveCfg = Debug|Any CPU
10797+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|arm64.Build.0 = Debug|Any CPU
10798+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x64.ActiveCfg = Debug|Any CPU
10799+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x64.Build.0 = Debug|Any CPU
10800+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x86.ActiveCfg = Debug|Any CPU
10801+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Debug|x86.Build.0 = Debug|Any CPU
10802+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|Any CPU.ActiveCfg = Release|Any CPU
10803+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|Any CPU.Build.0 = Release|Any CPU
10804+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|arm64.ActiveCfg = Release|Any CPU
10805+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|arm64.Build.0 = Release|Any CPU
10806+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x64.ActiveCfg = Release|Any CPU
10807+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x64.Build.0 = Release|Any CPU
10808+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x86.ActiveCfg = Release|Any CPU
10809+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13}.Release|x86.Build.0 = Release|Any CPU
1077410810
EndGlobalSection
1077510811
GlobalSection(SolutionProperties) = preSolution
1077610812
HideSolutionNode = FALSE
@@ -11653,6 +11689,8 @@ Global
1165311689
{B0A8E5D4-BC5A-448E-B222-431B6B2EB58E} = {05A169C7-4F20-4516-B10A-B13C5649D346}
1165411690
{15D08EA7-8C63-45FB-8B4D-C5F8E43B433E} = {05A169C7-4F20-4516-B10A-B13C5649D346}
1165511691
{433F91E4-E39D-4EB0-B798-2998B3969A2C} = {6126DCE4-9692-4EE2-B240-C65743572995}
11692+
{D2848C1B-4962-4B94-AC5F-A3C368C5B351} = {6126DCE4-9692-4EE2-B240-C65743572995}
11693+
{8A021D6D-7935-4AB3-BB47-38D4FF9B0D13} = {6126DCE4-9692-4EE2-B240-C65743572995}
1165611694
EndGlobalSection
1165711695
GlobalSection(ExtensibilityGlobals) = postSolution
1165811696
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

src/Components/Components.slnf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"src\\Components\\WebAssembly\\testassets\\HostedInAspNet.Client\\HostedInAspNet.Client.csproj",
3636
"src\\Components\\WebAssembly\\testassets\\HostedInAspNet.Server\\HostedInAspNet.Server.csproj",
3737
"src\\Components\\WebAssembly\\testassets\\StandaloneApp\\StandaloneApp.csproj",
38-
"src\\Components\\WebAssembly\\testassets\\ThreadingApp\\ThreadingApp.csproj",
3938
"src\\Components\\WebAssembly\\testassets\\ThreadingApp.Server\\ThreadingApp.Server.csproj",
39+
"src\\Components\\WebAssembly\\testassets\\ThreadingApp\\ThreadingApp.csproj",
4040
"src\\Components\\WebAssembly\\testassets\\Wasm.Prerendered.Client\\Wasm.Prerendered.Client.csproj",
4141
"src\\Components\\WebAssembly\\testassets\\Wasm.Prerendered.Server\\Wasm.Prerendered.Server.csproj",
4242
"src\\Components\\WebAssembly\\testassets\\WasmLinkerTest\\WasmLinkerTest.csproj",
@@ -54,6 +54,7 @@
5454
"src\\Components\\test\\testassets\\BasicTestApp\\BasicTestApp.csproj",
5555
"src\\Components\\test\\testassets\\Components.TestServer\\Components.TestServer.csproj",
5656
"src\\Components\\test\\testassets\\Components.WasmMinimal\\Components.WasmMinimal.csproj",
57+
"src\\Components\\test\\testassets\\Components.WasmRemoteAuthentication\\Components.WasmRemoteAuthentication.csproj",
5758
"src\\Components\\test\\testassets\\ComponentsApp.App\\ComponentsApp.App.csproj",
5859
"src\\Components\\test\\testassets\\ComponentsApp.Server\\ComponentsApp.Server.csproj",
5960
"src\\Components\\test\\testassets\\GlobalizationWasmApp\\GlobalizationWasmApp.csproj",

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

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

3737
var assembly = ApplicationAssembly ?? BuildWebHostMethod.Method.DeclaringType.Assembly;
38-
var sampleSitePath = DefaultGetContentRoot(assembly);
38+
var sampleSitePath = GetContentRootMethod(assembly);
3939

4040
var host = "127.0.0.1";
4141
if (E2ETestOptions.Instance.SauceTest)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<!--
44
Skip building and running the Components E2E tests in CI unless explicitly configured otherwise via
@@ -48,7 +48,6 @@
4848
</ItemGroup>
4949

5050
<ItemGroup>
51-
<ProjectReference Include="..\testassets\Components.TestServer\Components.TestServer.csproj" />
5251
<ProjectReference Include="..\..\WebAssembly\testassets\HostedInAspNet.Client\HostedInAspNet.Client.csproj" />
5352
<ProjectReference Include="..\..\WebAssembly\testassets\HostedInAspNet.Server\HostedInAspNet.Server.csproj" />
5453
<ProjectReference Include="..\..\WebAssembly\testassets\ThreadingApp.Server\ThreadingApp.Server.csproj" />
@@ -61,6 +60,7 @@
6160
<ProjectReference Include="..\testassets\BasicTestApp\BasicTestApp.csproj" />
6261
<ProjectReference Include="..\testassets\GlobalizationWasmApp\GlobalizationWasmApp.csproj" />
6362
<ProjectReference Include="..\..\WebAssembly\testassets\Wasm.Prerendered.Server\Wasm.Prerendered.Server.csproj" />
63+
<ProjectReference Include="..\testassets\Components.TestServer\Components.TestServer.csproj" />
6464
</ItemGroup>
6565

6666
<ItemGroup Condition="'$(TestTrimmedOrMultithreadingApps)' == 'true'">
@@ -92,6 +92,11 @@
9292
Include="..\..\WebAssembly\testassets\ThreadingApp\ThreadingApp.csproj"
9393
Targets="Build;Publish"
9494
Properties="BuildProjectReferences=false;TestTrimmedOrMultithreadingApps=false;PublishDir=$(MSBuildThisFileDirectory)$(OutputPath)trimmed-or-threading\ThreadingApp\;" />
95+
96+
<ProjectReference
97+
Include="..\testassets\Components.TestServer\Components.TestServer.csproj"
98+
Targets="Build;Publish"
99+
Properties="BuildProjectReferences=false;TestTrimmedOrMultithreadingApps=true;PublishDir=$(MSBuildThisFileDirectory)$(OutputPath)trimmed-or-threading\Components.TestServer\;" />
95100
</ItemGroup>
96101

97102
<!-- 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+
using System.Reflection;
5+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
6+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
8+
using Microsoft.AspNetCore.Hosting;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Hosting;
11+
using Microsoft.Extensions.Logging;
12+
using Microsoft.Extensions.Logging.Testing;
13+
using OpenQA.Selenium;
14+
using TestServer;
15+
using Xunit.Abstractions;
16+
17+
namespace Microsoft.AspNetCore.Components.E2ETest.Tests;
18+
19+
public class RemoteAuthenticationTest :
20+
ServerTestBase<BasicTestAppServerSiteFixture<RemoteAuthenticationStartup>>
21+
{
22+
public readonly bool TestTrimmedApps = typeof(ToggleExecutionModeServerFixture<>).Assembly
23+
.GetCustomAttributes<AssemblyMetadataAttribute>()
24+
.First(m => m.Key == "Microsoft.AspNetCore.E2ETesting.TestTrimmedOrMultithreadingApps")
25+
.Value == "true";
26+
27+
public RemoteAuthenticationTest(
28+
BrowserFixture browserFixture,
29+
BasicTestAppServerSiteFixture<RemoteAuthenticationStartup> serverFixture,
30+
ITestOutputHelper output)
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+
public void NavigateToLogin_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+
var heading = Browser.Exists(By.TagName("h1"));
50+
Browser.Equal("Hello, Jane Doe!", () => heading.Text);
51+
}
52+
53+
private static IHost BuildPublishedWebHost(string[] args) =>
54+
Host.CreateDefaultBuilder(args)
55+
.ConfigureLogging((ctx, lb) =>
56+
{
57+
TestSink sink = new TestSink();
58+
lb.AddProvider(new TestLoggerProvider(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+
private static string GetPublishedContentRoot(Assembly assembly)
69+
{
70+
var contentRoot = Path.Combine(AppContext.BaseDirectory, "trimmed-or-threading", assembly.GetName().Name);
71+
72+
if (!Directory.Exists(contentRoot))
73+
{
74+
throw new DirectoryNotFoundException($"Test is configured to use trimmed outputs, but trimmed outputs were not found in {contentRoot}.");
75+
}
76+
77+
return contentRoot;
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
private static string GetPublishedContentRoot(Assembly assembly)
5858
{
59-
var contentRoot = Path.Combine(AppContext.BaseDirectory, "trimmed", assembly.GetName().Name);
59+
var contentRoot = 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
@@ -28,11 +28,13 @@
2828
<Reference Include="Microsoft.AspNetCore.SignalR" />
2929
<Reference Include="Microsoft.AspNetCore.InternalTesting" />
3030
<Reference Include="Microsoft.Extensions.Hosting" />
31+
<Reference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" />
3132
</ItemGroup>
3233

3334
<ItemGroup>
3435
<ProjectReference Include="..\BasicTestApp\BasicTestApp.csproj" />
3536
<ProjectReference Include="..\Components.WasmMinimal\Components.WasmMinimal.csproj" />
37+
<ProjectReference Include="..\Components.WasmRemoteAuthentication\Components.WasmRemoteAuthentication.csproj" />
3638
</ItemGroup>
3739

3840
<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
var createIndividualHosts = new Dictionary<string, (IHost host, string basePath)>
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+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<base href="/subdir/" />
7+
8+
<HeadOutlet @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
9+
</head>
10+
11+
<body>
12+
<Components.WasmRemoteAuthentication.Routes @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
13+
<script src="_framework/blazor.web.js" autostart="false"></script>
14+
<script src="_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>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
using System.Globalization;
5+
using System.Reflection;
6+
using Components.TestServer.RazorComponents;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.IdentityModel.JsonWebTokens;
9+
using Microsoft.IdentityModel.Tokens;
10+
11+
namespace TestServer;
12+
13+
public class RemoteAuthenticationStartup
14+
{
15+
public void ConfigureServices(IServiceCollection services)
16+
{
17+
services.AddRazorComponents()
18+
.AddInteractiveWebAssemblyComponents();
19+
}
20+
21+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
22+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
23+
{
24+
app.Map("/subdir", app =>
25+
{
26+
app.UseStaticFiles();
27+
app.UseRouting();
28+
app.UseAntiforgery();
29+
app.UseEndpoints(endpoints =>
30+
{
31+
endpoints.MapRazorComponents<RemoteAuthenticationApp>()
32+
.AddAdditionalAssemblies(Assembly.Load("Components.WasmRemoteAuthentication"))
33+
.AddInteractiveWebAssemblyRenderMode(options => options.PathPrefix = "/WasmRemoteAuthentication");
34+
35+
var oidcEndpoints = endpoints.MapGroup("oidc");
36+
37+
// This is designed to test a single login at a time.
38+
var issuer = "";
39+
oidcEndpoints.MapGet(".well-known/openid-configuration", (HttpRequest request, [FromHeader] string host) =>
40+
{
41+
issuer = $"{(request.IsHttps ? "https" : "http")}://{host}";
42+
return Results.Json(new
43+
{
44+
issuer,
45+
authorization_endpoint = $"{issuer}/subdir/oidc/authorize",
46+
token_endpoint = $"{issuer}/subdir/oidc/token",
47+
});
48+
});
49+
50+
var lastCode = "";
51+
oidcEndpoints.MapGet("authorize", (string redirect_uri, string? state, string? prompt, bool? preservedExtraQueryParams) =>
52+
{
53+
// Require interaction so silent sign-in does not skip RedirectToLogin.razor.
54+
if (prompt == "none")
55+
{
56+
return Results.Redirect($"{redirect_uri}?error=interaction_required&state={state}");
57+
}
58+
59+
// Verify that the extra query parameters added by RedirectToLogin.razor are preserved.
60+
if (preservedExtraQueryParams != true)
61+
{
62+
return Results.Redirect($"{redirect_uri}?error=invalid_request&error_description=extraQueryParams%20not%20preserved&state={state}");
63+
}
64+
65+
lastCode = Random.Shared.Next().ToString(CultureInfo.InvariantCulture);
66+
return Results.Redirect($"{redirect_uri}?code={lastCode}&state={state}");
67+
});
68+
69+
var jwtHandler = new JsonWebTokenHandler();
70+
oidcEndpoints.MapPost("token", ([FromForm] string code) =>
71+
{
72+
if (string.IsNullOrEmpty(lastCode) && code != lastCode)
73+
{
74+
return Results.BadRequest("Bad code");
75+
}
76+
77+
return Results.Json(new
78+
{
79+
token_type = "Bearer",
80+
scope = "openid profile",
81+
expires_in = 3600,
82+
id_token = jwtHandler.CreateToken(new SecurityTokenDescriptor
83+
{
84+
Issuer = issuer,
85+
Audience = "s6BhdRkqt3",
86+
Claims = new Dictionary<string, object>
87+
{
88+
["sub"] = "248289761001",
89+
["name"] = "Jane Doe",
90+
},
91+
}),
92+
});
93+
}).DisableAntiforgery();
94+
});
95+
});
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<StaticWebAssetBasePath>WasmRemoteAuthentication</StaticWebAssetBasePath>
8+
</PropertyGroup>
9+
10+
<PropertyGroup Condition="'$(TestTrimmedOrMultithreadingApps)' == 'true'">
11+
<!-- Avoid spending time brotli compression publish output.-->
12+
<_BlazorBrotliCompressionLevel>NoCompression</_BlazorBrotliCompressionLevel>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
17+
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@page "/authentication/{action}"
2+
3+
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
4+
5+
<RemoteAuthenticatorView Action="@Action" />
6+
7+
@code {
8+
[Parameter] public string? Action { get; set; }
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@page "/test-remote-authentication"
2+
3+
@using Microsoft.AspNetCore.Components.Authorization
4+
5+
<AuthorizeView>
6+
<Authorized>
7+
<h1>Hello, @context.User.Identity?.Name!</h1>
8+
</Authorized>
9+
<NotAuthorized>
10+
@* Do this rather than rely on the [Authorize] attribute to avoid endpoint routing. *@
11+
<RedirectToLogin />
12+
</NotAuthorized>
13+
</AuthorizeView>

0 commit comments

Comments
 (0)