Skip to content

Commit 5ce24a6

Browse files
committed
Tests passing
1 parent 4d952dd commit 5ce24a6

File tree

7 files changed

+14
-56
lines changed

7 files changed

+14
-56
lines changed

src/Components/Browser.JS/dist/Release/blazor.server.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Server/src/Authentication/CircuitAuthenticationHandler.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
4848
{
4949
if (CircuitIdFactory.ValidateCircuitId(circuitId, cookie, out var parsedId))
5050
{
51-
var identity = new ClaimsIdentity(AuthenticationType);
51+
var identity = new ClaimsIdentity();
5252
identity.AddClaim(new Claim(IdClaimType, parsedId.RequestToken));
5353
var principal = new ClaimsPrincipal();
5454
principal.AddIdentity(identity);
@@ -88,21 +88,6 @@ protected override Task HandleSignOutAsync(AuthenticationProperties properties)
8888
throw new InvalidOperationException("Sign out is not supported.");
8989
}
9090

91-
private string GetId(string value)
92-
{
93-
try
94-
{
95-
CircuitId result = CircuitIdFactory.FromCookieValue(value);
96-
return result.RequestToken;
97-
}
98-
catch
99-
{
100-
// Cookie didn't have a valid format, treating them as if it didn't exist.
101-
// We might want to log here that something went wrong.
102-
return null;
103-
}
104-
}
105-
10691
internal static void AttachCircuitId(HttpContext httpContext, CircuitId circuitId)
10792
{
10893
var principal = new ClaimsPrincipal();

src/Components/Server/src/Builder/ComponentEndpointRouteBuilderExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public static ComponentEndpointConventionBuilder MapBlazorHub(this IEndpointRout
4949
}
5050

5151
endpoints.MapStartCircuitEndpoint(ComponentHub.DefaultPath + "/start");
52-
return new ComponentEndpointConventionBuilder(endpoints.MapHub<ComponentHub>(ComponentHub.DefaultPath, configureOptions));
52+
return new ComponentEndpointConventionBuilder(endpoints.MapHub<ComponentHub>(ComponentHub.DefaultPath, configureOptions))
53+
.RequireAuthorization(CircuitAuthenticationHandler.AuthenticationType);
5354
}
5455

5556
/// <summary>

src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollecti
5353
CircuitAuthenticationHandler.AuthenticationType,
5454
_ => { });
5555

56+
services.AddAuthorization();
57+
5658
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<AuthorizationOptions>, ConfigureCircuitAuthorization>());
5759
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<CircuitOptions>, ConfigureCircuitAuthenticationPolicy>());
5860

src/Components/test/testassets/ComponentsApp.Server/Pages/Index.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
</head>
1414
<body>
1515
<app>@(await Html.RenderComponentAsync<App>(new { Name = "Guest" }))</app>
16-
<banner></banner>
1716
<script src="_framework/blazor.server.js" autostart="false"></script>
1817
<script>
1918
Blazor.start({
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Security.Claims;
5-
using System.Text.Encodings.Web;
6-
using System.Threading.Tasks;
7-
using Microsoft.AspNetCore.Authentication;
84
using Microsoft.AspNetCore.Builder;
95
using Microsoft.AspNetCore.Components.Server.Circuits;
106
using Microsoft.AspNetCore.Hosting;
117
using Microsoft.Extensions.DependencyInjection;
128
using Microsoft.Extensions.Hosting;
13-
using Microsoft.Extensions.Logging;
14-
using Microsoft.Extensions.Options;
159

1610
namespace ComponentsApp.Server
1711
{
@@ -22,14 +16,6 @@ public void ConfigureServices(IServiceCollection services)
2216
services.AddMvc();
2317
services.AddSingleton<CircuitHandler, LoggingCircuitHandler>();
2418
services.AddServerSideBlazor();
25-
//services.AddSignalR().AddAzureSignalR(o =>
26-
//{
27-
// o.ServerStickyMode = ServerStickyMode.Required;
28-
// o.ConnectionString = "Endpoint=https://antifoguertysignalr.service.signalr.net;AccessKey=vdGlVP/IMKLjlRbDOZX6v8Ce6XJ1o1OEayz+nWuTM3U=;Version=1.0;";
29-
//});
30-
31-
services.AddAuthentication("Test")
32-
.AddScheme<TestAuthenticationOptions, TestScheme>("Test", o => { });
3319

3420
services.AddSingleton<WeatherForecastService, DefaultWeatherForecastService>();
3521
}
@@ -51,29 +37,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5137
{
5238
endpoints.MapRazorPages();
5339
endpoints.MapControllers();
54-
endpoints.MapBlazorHub<App.Banner>(selector: "banner")
55-
.RequireAuthorization("Circuit");
40+
endpoints.MapBlazorHub();
5641
endpoints.MapFallbackToPage("/Index");
5742
});
5843
}
5944
}
60-
61-
public class TestScheme : AuthenticationHandler<TestAuthenticationOptions>
62-
{
63-
public TestScheme(
64-
IOptionsMonitor<TestAuthenticationOptions> options, ILoggerFactory logger,
65-
UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
66-
{
67-
}
68-
69-
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
70-
{
71-
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(
72-
new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("some", "claim") }, "Test")), "Test")));
73-
}
74-
}
75-
76-
public class TestAuthenticationOptions : AuthenticationSchemeOptions
77-
{
78-
}
7945
}

src/Components/test/testassets/TestServer/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6767

6868
subdirApp.UseRouting();
6969

70+
subdirApp.UseAuthorization();
71+
7072
subdirApp.UseEndpoints(endpoints =>
7173
{
7274
endpoints.MapBlazorHub(typeof(Index), selector: "root");
@@ -90,6 +92,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
9092
subdirApp.UsePathBase("/prerendered");
9193
subdirApp.UseStaticFiles();
9294
subdirApp.UseRouting();
95+
96+
subdirApp.UseAuthorization();
97+
9398
subdirApp.UseEndpoints(endpoints =>
9499
{
95100
endpoints.MapFallbackToPage("/PrerenderedHost");

0 commit comments

Comments
 (0)