我正在寻找安全存储在blazor webassembly应用程序中的应用程序秘密的方法。我们可以在下面的MSDN文档中找到服务器端应用程序的详细信息。
https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1&tabs=windows
我们如何将这些秘密用于Blazor WebAssembly应用程序,它完全运行在客户端浏览器中?
我的基本场景是,需要将密码、产品密钥(许可密钥)信息保留在应用程序代码之外。例如,我们在Program.cs的静态main方法中加载许可。
https://i.stack.imgur.com/kCrV1.png
public class Program
{
public static async Task Main(string[] args)
{
//want to access the product key here and need to avoid hardcoding
SomeThirdPartyLibrary.RegisterLicense("product-key");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();
}我已经搜索了blazor的文档,但没有找到这方面的任何细节。请帮助我找到在Blazor webassembly中解决这个问题的推荐方法。
(对于服务器端,我们有多种选择,但对于客户端,推荐的方式是什么)
发布于 2020-07-03 00:44:49
如果你把它存储在客户端,它是不安全的。
有一个实验性的MS nuget包,声称可以通过加密来确保存储安全-- Microsoft.AspNetCore.ProtectedBrowserStorage
您可以在这里阅读如何使用它https://docs.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-3.1
发布于 2020-08-05 15:53:48
可以通过使用MemoryConfigurationSource来使用内存配置
示例:
var appsettings = new Dictionary<string, string>()
{
{ "API:Key", "12345" }
};
var config = new MemoryConfigurationSource(InitialData = appsettings);
builder.Configuration.Add(memoryConfig);然后,无论您想使用它,只需@inject configuration (在剃刀页面中)或在您的类程序中如下所示:
builder.Configuration.GetValue<string>("API:Key")https://stackoverflow.com/questions/62700005
复制相似问题