Skip to content

Commit 6469251

Browse files
authored
Move ProtectedBrowserStorage to the shared fx (#25557)
* Move ProtectedBrowserStorage to the shared fx * Fixups * Fixup
1 parent 9f5276d commit 6469251

28 files changed

+51
-156
lines changed

AspNetCore.sln

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,12 +1487,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Diagno
14871487
EndProject
14881488
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.JSInterop.Tests", "src\JSInterop\Microsoft.JSInterop\test\Microsoft.JSInterop.Tests.csproj", "{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}"
14891489
EndProject
1490-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProtectedBrowserStorage", "ProtectedBrowserStorage", "{1B06FD32-3A1D-46A4-B2AF-99159FAD8127}"
1491-
EndProject
1492-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.ProtectedBrowserStorage", "src\Components\ProtectedBrowserStorage\src\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj", "{9059AC97-7547-4CC1-A076-680CBCCC1F33}"
1493-
EndProject
1494-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests", "src\Components\ProtectedBrowserStorage\test\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests.csproj", "{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}"
1495-
EndProject
14961490
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Configuration.KeyPerFile", "src\Configuration.KeyPerFile\src\Microsoft.Extensions.Configuration.KeyPerFile.csproj", "{498A4F54-F11A-46C5-A58D-09DE56C6A034}"
14971491
EndProject
14981492
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configuration.KeyPerFile", "Configuration.KeyPerFile", "{AEB1933E-9369-4305-B20E-F186F888158F}"
@@ -7127,30 +7121,6 @@ Global
71277121
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}.Release|x64.Build.0 = Release|Any CPU
71287122
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}.Release|x86.ActiveCfg = Release|Any CPU
71297123
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}.Release|x86.Build.0 = Release|Any CPU
7130-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7131-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|Any CPU.Build.0 = Debug|Any CPU
7132-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x64.ActiveCfg = Debug|Any CPU
7133-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x64.Build.0 = Debug|Any CPU
7134-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x86.ActiveCfg = Debug|Any CPU
7135-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x86.Build.0 = Debug|Any CPU
7136-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|Any CPU.ActiveCfg = Release|Any CPU
7137-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|Any CPU.Build.0 = Release|Any CPU
7138-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x64.ActiveCfg = Release|Any CPU
7139-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x64.Build.0 = Release|Any CPU
7140-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x86.ActiveCfg = Release|Any CPU
7141-
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x86.Build.0 = Release|Any CPU
7142-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7143-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
7144-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x64.ActiveCfg = Debug|Any CPU
7145-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x64.Build.0 = Debug|Any CPU
7146-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x86.ActiveCfg = Debug|Any CPU
7147-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x86.Build.0 = Debug|Any CPU
7148-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
7149-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|Any CPU.Build.0 = Release|Any CPU
7150-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x64.ActiveCfg = Release|Any CPU
7151-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x64.Build.0 = Release|Any CPU
7152-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x86.ActiveCfg = Release|Any CPU
7153-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x86.Build.0 = Release|Any CPU
71547124
{498A4F54-F11A-46C5-A58D-09DE56C6A034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71557125
{498A4F54-F11A-46C5-A58D-09DE56C6A034}.Debug|Any CPU.Build.0 = Debug|Any CPU
71567126
{498A4F54-F11A-46C5-A58D-09DE56C6A034}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -8053,9 +8023,6 @@ Global
80538023
{55CACC1F-FE96-47C8-8073-91F4CAA55C75} = {2A91479A-4ABE-4BB7-9A5E-CA3B9CCFC69E}
80548024
{7509AA1E-3093-4BEE-984F-E11579E98A11} = {7CB09412-C9B0-47E8-A8C3-311AA4CFDE04}
80558025
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E} = {16898702-3E33-41C1-B8D8-4CE3F1D46BD9}
8056-
{1B06FD32-3A1D-46A4-B2AF-99159FAD8127} = {60D51C98-2CC0-40DF-B338-44154EFEE2FF}
8057-
{9059AC97-7547-4CC1-A076-680CBCCC1F33} = {1B06FD32-3A1D-46A4-B2AF-99159FAD8127}
8058-
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5} = {1B06FD32-3A1D-46A4-B2AF-99159FAD8127}
80598026
{498A4F54-F11A-46C5-A58D-09DE56C6A034} = {AEB1933E-9369-4305-B20E-F186F888158F}
80608027
{AEB1933E-9369-4305-B20E-F186F888158F} = {017429CC-C5FB-48B4-9C46-034E29EE2F06}
80618028
{B9D37BCF-80D1-489D-9FC6-55191FDBB033} = {AEB1933E-9369-4305-B20E-F186F888158F}

eng/ProjectReferences.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components" ProjectPath="$(RepoRoot)src\Components\Components\src\Microsoft.AspNetCore.Components.csproj" />
141141
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.Forms" ProjectPath="$(RepoRoot)src\Components\Forms\src\Microsoft.AspNetCore.Components.Forms.csproj" />
142142
<ProjectReferenceProvider Include="Ignitor" ProjectPath="$(RepoRoot)src\Components\Ignitor\src\Ignitor.csproj" />
143-
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.ProtectedBrowserStorage" ProjectPath="$(RepoRoot)src\Components\ProtectedBrowserStorage\src\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj" />
144143
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.Server" ProjectPath="$(RepoRoot)src\Components\Server\src\Microsoft.AspNetCore.Components.Server.csproj" />
145144
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.Web.Extensions" ProjectPath="$(RepoRoot)src\Components\Web.Extensions\src\Microsoft.AspNetCore.Components.Web.Extensions.csproj" />
146145
<ProjectReferenceProvider Include="Microsoft.Authentication.WebAssembly.Msal" ProjectPath="$(RepoRoot)src\Components\WebAssembly\Authentication.Msal\src\Microsoft.Authentication.WebAssembly.Msal.csproj" />

src/Components/Components.slnf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@
111111
"src\\Components\\WebAssembly\\Sdk\\src\\Microsoft.NET.Sdk.BlazorWebAssembly.csproj",
112112
"src\\Components\\WebAssembly\\Sdk\\test\\Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj",
113113
"src\\Components\\WebAssembly\\Sdk\\integrationtests\\Microsoft.NET.Sdk.BlazorWebAssembly.IntegrationTests.csproj",
114-
"src\\JSInterop\\Microsoft.JSInterop\\src\\Microsoft.JSInterop.csproj",
115-
"src\\Components\\ProtectedBrowserStorage\\src\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj",
116-
"src\\Components\\ProtectedBrowserStorage\\test\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests.csproj"
114+
"src\\JSInterop\\Microsoft.JSInterop\\src\\Microsoft.JSInterop.csproj"
117115
]
118116
}
119117
}

src/Components/ComponentsNoDeps.slnf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
"src\\Components\\test\\testassets\\BasicTestApp\\BasicTestApp.csproj",
4646
"src\\Components\\test\\testassets\\ComponentsApp.Server\\ComponentsApp.Server.csproj",
4747
"src\\Components\\test\\testassets\\TestContentPackage\\TestContentPackage.csproj",
48-
"src\\Components\\test\\testassets\\TestServer\\Components.TestServer.csproj",
49-
"src\\Components\\ProtectedBrowserStorage\\src\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj",
50-
"src\\Components\\ProtectedBrowserStorage\\test\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests.csproj"
48+
"src\\Components\\test\\testassets\\TestServer\\Components.TestServer.csproj"
5149
]
5250
}
5351
}

src/Components/ProtectedBrowserStorage/src/Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Components/ProtectedBrowserStorage/src/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/Components/ProtectedBrowserStorage/src/ProtectedBrowserStorage/ProtectedBrowserStorageServiceCollectionExtensions.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Components/ProtectedBrowserStorage/test/Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests.csproj

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.AspNetCore.Components.Server;
1010
using Microsoft.AspNetCore.Components.Server.BlazorPack;
1111
using Microsoft.AspNetCore.Components.Server.Circuits;
12+
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
1213
using Microsoft.AspNetCore.SignalR.Protocol;
1314
using Microsoft.Extensions.DependencyInjection.Extensions;
1415
using Microsoft.Extensions.Options;
@@ -33,6 +34,9 @@ public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollecti
3334

3435
services.AddDataProtection();
3536

37+
services.TryAddScoped<ProtectedLocalStorage>();
38+
services.TryAddScoped<ProtectedSessionStorage>();
39+
3640
// This call INTENTIONALLY uses the AddHubOptions on the SignalR builder, because it will merge
3741
// the global HubOptions before running the configure callback. We want to ensure that happens
3842
// once. Our AddHubOptions method doesn't do this.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
using System;
55
using System.Collections.Concurrent;
66
using System.Runtime.InteropServices;
7-
using System.Runtime.Versioning;
87
using System.Text.Json;
98
using System.Threading.Tasks;
109
using Microsoft.AspNetCore.DataProtection;
1110
using Microsoft.JSInterop;
1211

13-
namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
12+
namespace Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
1413
{
1514

1615
/// <summary>
1716
/// Provides mechanisms for storing and retrieving data in the browser storage.
1817
/// </summary>
19-
[UnsupportedOSPlatform("browser")]
2018
public abstract class ProtectedBrowserStorage
2119
{
2220
private readonly string _storeName;
@@ -31,7 +29,7 @@ private readonly ConcurrentDictionary<string, IDataProtector> _cachedDataProtect
3129
/// <param name="storeName">The name of the store in which the data should be stored.</param>
3230
/// <param name="jsRuntime">The <see cref="IJSRuntime"/>.</param>
3331
/// <param name="dataProtectionProvider">The <see cref="IDataProtectionProvider"/>.</param>
34-
protected ProtectedBrowserStorage(string storeName, IJSRuntime jsRuntime, IDataProtectionProvider dataProtectionProvider)
32+
private protected ProtectedBrowserStorage(string storeName, IJSRuntime jsRuntime, IDataProtectionProvider dataProtectionProvider)
3533
{
3634
// Performing data protection on the client would give users a false sense of security, so we'll prevent this.
3735
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
@@ -155,8 +153,8 @@ private TValue Unprotect<TValue>(string purpose, string protectedJson)
155153
private ValueTask SetProtectedJsonAsync(string key, string protectedJson)
156154
=> _jsRuntime.InvokeVoidAsync($"{_storeName}.setItem", key, protectedJson);
157155

158-
private ValueTask<string> GetProtectedJsonAsync(string key)
159-
=> _jsRuntime.InvokeAsync<string>($"{_storeName}.getItem", key);
156+
private ValueTask<string?> GetProtectedJsonAsync(string key)
157+
=> _jsRuntime.InvokeAsync<string?>($"{_storeName}.getItem", key);
160158

161159
// IDataProtect isn't disposable, so we're fine holding these indefinitely.
162160
// Only a bounded number of them will be created, as the 'key' values should

0 commit comments

Comments
 (0)