Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit cc4f87f

Browse files
committed
Formatting and copyright headers
1 parent 560550b commit cc4f87f

11 files changed

+105
-62
lines changed

src/Duende.Bff.Blazor.Client/AntiforgeryHandler.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
namespace Duende.Bff.Blazor.Client;
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
4+
namespace Duende.Bff.Blazor.Client;
25

36
public class AntiforgeryHandler : DelegatingHandler
47
{
5-
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
8+
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
9+
CancellationToken cancellationToken)
610
{
711
request.Headers.Add("X-CSRF", "1");
812
return base.SendAsync(request, cancellationToken);

src/Duende.Bff.Blazor.Client/BffBlazorOptions.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
namespace Duende.Bff.Blazor.Client;
25

36
/// <summary>
4-
/// Options for Blazor BFF
7+
/// Options for Blazor BFF
58
/// </summary>
69
public class BffBlazorOptions
710
{
811
/// <summary>
9-
/// The base path to use for remote APIs.
12+
/// The base path to use for remote APIs.
1013
/// </summary>
1114
public string RemoteApiPath { get; set; } = "remote-apis/";
12-
15+
1316
/// <summary>
14-
/// The base address to use for remote APIs. If unset (the default), the
15-
/// blazor hosting environment's base address is used.
17+
/// The base address to use for remote APIs. If unset (the default), the
18+
/// blazor hosting environment's base address is used.
1619
/// </summary>
1720
public string? RemoteApiBaseAddress { get; set; } = null;
1821

src/Duende.Bff.Blazor.Client/BffClientAuthenticationStateProvider.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Net.Http.Json;
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
4+
using System.Net.Http.Json;
25
using System.Security.Claims;
36
using Microsoft.Extensions.Logging;
47
using Microsoft.AspNetCore.Components;
@@ -27,10 +30,11 @@ public BffClientAuthenticationStateProvider(
2730
_client = factory.CreateClient("BffAuthenticationStateProvider");
2831
_logger = logger;
2932
_cachedUser = GetPersistedUser(state);
30-
if (_cachedUser.Identity?.IsAuthenticated == true)
33+
if (_cachedUser.Identity?.IsAuthenticated == true)
3134
{
3235
_userLastCheck = DateTimeOffset.Now;
3336
}
37+
3438
_options = options.Value;
3539
}
3640

@@ -106,7 +110,7 @@ private async Task<ClaimsPrincipal> FetchUser()
106110
foreach (var claim in claims)
107111
{
108112
identity.AddClaim(new Claim(claim.Type, claim.Value.ToString() ?? "no value"));
109-
}
113+
}
110114
}
111115

112116
return new ClaimsPrincipal(identity);
@@ -131,4 +135,4 @@ private ClaimsPrincipal GetPersistedUser(PersistentComponentState state)
131135

132136
return lite.ToClaimsPrincipal();
133137
}
134-
}
138+
}
+9-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
namespace Duende.Bff.Blazor.Client;
25

36
// TODO - Consider consolidating this and Duende.Bff.ClaimLite
47

58
/// <summary>
6-
/// Serialization friendly claim
9+
/// Serialization friendly claim
710
/// </summary>
811
public class ClaimLite
912
{
1013
/// <summary>
11-
/// The type
14+
/// The type
1215
/// </summary>
1316
public string Type { get; init; } = default!;
14-
17+
1518
/// <summary>
16-
/// The value
19+
/// The value
1720
/// </summary>
1821
public string Value { get; init; } = default!;
1922

2023
/// <summary>
21-
/// The value type
24+
/// The value type
2225
/// </summary>
2326
public string? ValueType { get; init; }
24-
}
27+
}

src/Duende.Bff.Blazor.Client/ClaimsLiteExtensions.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
using System.Security.Claims;
25

36
namespace Duende.Bff.Blazor.Client;
47

58
public static class ClaimsLiteExtensions
69
{
710
/// <summary>
8-
/// Converts a ClaimsPrincipalLite to ClaimsPrincipal
11+
/// Converts a ClaimsPrincipalLite to ClaimsPrincipal
912
/// </summary>
1013
public static ClaimsPrincipal ToClaimsPrincipal(this ClaimsPrincipalLite principal)
1114
{
12-
var claims = principal.Claims.Select(x => new Claim(x.Type, x.Value, x.ValueType ?? ClaimValueTypes.String)).ToArray();
13-
var id = new ClaimsIdentity(claims, principal.AuthenticationType, principal.NameClaimType, principal.RoleClaimType);
15+
var claims = principal.Claims.Select(x => new Claim(x.Type, x.Value, x.ValueType ?? ClaimValueTypes.String))
16+
.ToArray();
17+
var id = new ClaimsIdentity(claims, principal.AuthenticationType, principal.NameClaimType,
18+
principal.RoleClaimType);
1419

1520
return new ClaimsPrincipal(id);
1621
}
1722

1823
/// <summary>
19-
/// Converts a ClaimsPrincipal to ClaimsPrincipalLite
24+
/// Converts a ClaimsPrincipal to ClaimsPrincipalLite
2025
/// </summary>
2126
public static ClaimsPrincipalLite ToClaimsPrincipalLite(this ClaimsPrincipal principal)
2227
{
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
namespace Duende.Bff.Blazor.Client;
25

36
/// <summary>
4-
/// Serialization friendly ClaimsPrincipal
7+
/// Serialization friendly ClaimsPrincipal
58
/// </summary>
69
public class ClaimsPrincipalLite
710
{
811
/// <summary>
9-
/// The authentication type
12+
/// The authentication type
1013
/// </summary>
1114
public string? AuthenticationType { get; init; }
1215

1316
/// <summary>
14-
/// The name claim type
17+
/// The name claim type
1518
/// </summary>
1619
public string? NameClaimType { get; init; }
1720

1821
/// <summary>
19-
/// The role claim type
22+
/// The role claim type
2023
/// </summary>
2124
public string? RoleClaimType { get; init; }
2225

2326
/// <summary>
24-
/// The claims
27+
/// The claims
2528
/// </summary>
2629
public ClaimLite[] Claims { get; init; } = default!;
27-
}
30+
}

src/Duende.Bff.Blazor.Client/ServiceCollectionExtensions.cs

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
using Microsoft.AspNetCore.Components.Authorization;
25
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
36
using Microsoft.Extensions.DependencyInjection;
@@ -7,9 +10,10 @@ namespace Duende.Bff.Blazor.Client;
710

811
public static class ServiceCollectionExtensions
912
{
10-
public static IServiceCollection AddBff(this IServiceCollection services, Action<BffBlazorOptions>? configureAction = null)
13+
public static IServiceCollection AddBff(this IServiceCollection services,
14+
Action<BffBlazorOptions>? configureAction = null)
1115
{
12-
if(configureAction != null)
16+
if (configureAction != null)
1317
{
1418
services.Configure(configureAction);
1519
}
@@ -24,14 +28,14 @@ public static IServiceCollection AddBff(this IServiceCollection services, Actio
2428
var baseAddress = GetBaseAddress(sp);
2529
client.BaseAddress = new Uri(baseAddress);
2630
}).AddHttpMessageHandler<AntiforgeryHandler>();
27-
31+
2832
return services;
2933
}
3034

3135
private static string GetBaseAddress(IServiceProvider sp)
3236
{
3337
var opt = sp.GetRequiredService<IOptions<BffBlazorOptions>>();
34-
if(opt.Value.RemoteApiBaseAddress != null)
38+
if (opt.Value.RemoteApiBaseAddress != null)
3539
{
3640
return opt.Value.RemoteApiBaseAddress;
3741
}
@@ -48,7 +52,8 @@ private static string GetRemoteApiPath(IServiceProvider sp)
4852
return opt.Value.RemoteApiPath;
4953
}
5054

51-
private static Action<IServiceProvider, HttpClient> SetBaseAddressInConfigureClient(Action<IServiceProvider, HttpClient>? configureClient)
55+
private static Action<IServiceProvider, HttpClient> SetBaseAddressInConfigureClient(
56+
Action<IServiceProvider, HttpClient>? configureClient)
5257
{
5358
return (sp, client) =>
5459
{
@@ -57,7 +62,8 @@ private static Action<IServiceProvider, HttpClient> SetBaseAddressInConfigureCli
5762
};
5863
}
5964

60-
private static Action<IServiceProvider, HttpClient> SetBaseAddressInConfigureClient(Action<HttpClient>? configureClient)
65+
private static Action<IServiceProvider, HttpClient> SetBaseAddressInConfigureClient(
66+
Action<HttpClient>? configureClient)
6167
{
6268
return (sp, client) =>
6369
{
@@ -81,37 +87,43 @@ private static void SetBaseAddress(IServiceProvider sp, HttpClient client)
8187
{
8288
remoteApiPath = remoteApiPath.Substring(1);
8389
}
90+
8491
if (!remoteApiPath.EndsWith("/"))
8592
{
8693
remoteApiPath += "/";
8794
}
8895
}
96+
8997
client.BaseAddress = new Uri(new Uri(baseAddress), remoteApiPath);
9098
}
9199

92-
public static IHttpClientBuilder AddRemoteApiHttpClient(this IServiceCollection services, string clientName, Action<HttpClient> configureClient)
100+
public static IHttpClientBuilder AddRemoteApiHttpClient(this IServiceCollection services, string clientName,
101+
Action<HttpClient> configureClient)
93102
{
94-
return services.AddHttpClient(clientName, SetBaseAddressInConfigureClient(configureClient))
103+
return services.AddHttpClient(clientName, SetBaseAddressInConfigureClient(configureClient))
95104
.AddHttpMessageHandler<AntiforgeryHandler>();
96105
}
97106

98-
public static IHttpClientBuilder AddRemoteApiHttpClient(this IServiceCollection services, string clientName, Action<IServiceProvider, HttpClient>? configureClient = null)
107+
public static IHttpClientBuilder AddRemoteApiHttpClient(this IServiceCollection services, string clientName,
108+
Action<IServiceProvider, HttpClient>? configureClient = null)
99109
{
100110
return services.AddHttpClient(clientName, SetBaseAddressInConfigureClient(configureClient))
101-
.AddHttpMessageHandler<AntiforgeryHandler>();
111+
.AddHttpMessageHandler<AntiforgeryHandler>();
102112
}
103-
104-
public static IHttpClientBuilder AddRemoteApiHttpClient<T>(this IServiceCollection services, Action<HttpClient> configureClient)
113+
114+
public static IHttpClientBuilder AddRemoteApiHttpClient<T>(this IServiceCollection services,
115+
Action<HttpClient> configureClient)
105116
where T : class
106117
{
107118
return services.AddHttpClient<T>(SetBaseAddressInConfigureClient(configureClient))
108119
.AddHttpMessageHandler<AntiforgeryHandler>();
109120
}
110121

111-
public static IHttpClientBuilder AddRemoteApiHttpClient<T>(this IServiceCollection services, Action<IServiceProvider, HttpClient>? configureClient = null)
122+
public static IHttpClientBuilder AddRemoteApiHttpClient<T>(this IServiceCollection services,
123+
Action<IServiceProvider, HttpClient>? configureClient = null)
112124
where T : class
113125
{
114126
return services.AddHttpClient<T>(SetBaseAddressInConfigureClient(configureClient))
115-
.AddHttpMessageHandler<AntiforgeryHandler>();
127+
.AddHttpMessageHandler<AntiforgeryHandler>();
116128
}
117-
}
129+
}

src/Duende.Bff.Blazor/BffBuilderExtensions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
using Microsoft.AspNetCore.Builder;
25
using Microsoft.AspNetCore.Components.Authorization;
36
using Microsoft.Extensions.DependencyInjection;

src/Duende.Bff.Blazor/CaptureManagementClaimsCookieEvents.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
using System.Security.Claims;
25
using Microsoft.AspNetCore.Authentication.Cookies;
36

@@ -20,7 +23,6 @@ public override async Task ValidatePrincipal(CookieValidatePrincipalContext cont
2023

2124
if (context.Principal?.Identity is ClaimsIdentity id)
2225
{
23-
2426
foreach (var claim in managementClaims)
2527
{
2628
if (context.Principal.Claims.Any(c => c.Type == claim.type) != true)

src/Duende.Bff.Blazor/PersistingAuthenticationStateProvider.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
14
using System.Diagnostics;
25
using System.Security.Claims;
36
using Duende.Bff.Blazor.Client;
@@ -76,11 +79,11 @@ private async Task OnPersistingAsync()
7679
};
7780

7881
_logger.LogDebug("Persisting Authentication State");
79-
82+
8083
_state.PersistAsJson(nameof(ClaimsPrincipalLite), principal);
8184
}
8285

83-
86+
8487
public void Dispose()
8588
{
8689
_subscription.Dispose();

0 commit comments

Comments
 (0)