Blazor-app.UseIdentityServer();带有.pfx密钥文件-解析数字时遇到意外字符 [英] Blazor - app.UseIdentityServer(); with .pfx key file - Unexpected character encountered while parsing number

查看:27
本文介绍了Blazor-app.UseIdentityServer();带有.pfx密钥文件-解析数字时遇到意外字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建了一个新的Blazor WebAssembly应用程序,该应用程序具有在.NET 5中托管的个人用户帐户、应用程序内用户帐户和ASP.NET核心。将我的应用程序部署到Azure应用程序服务时,我收到以下错误:

对象引用未设置为对象的实例。在 Microsoft.Extensions.DependencyInjection.IdentityServerBuilderConfigurationExtensions

阅读这些链接时,我必须为IdentityServer提供我自己的生产证书:

Blazor Web Assembly App .Net Core Hosted: publish runtime error

https://stackoverflow.com/a/56904000/3850405

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-5.0#example-deploy-to-azure-app-service

然后我创建了一个类似这样的.pfx文件,并且我已验证该文件是否正常工作,并且我的密码是否正确。

https://stackoverflow.com/a/48790088/3850405

然后我将.pfx文件放在我的Server项目根文件夹中,并将Copy to Output Directory标记为Copy Always

然后我将appsettings.json更新为如下所示:

  "IdentityServer": {
    "Clients": {
      "BlazorTest.Client": {
        "Profile": "IdentityServerSPA"
      }
    },
    "Key": {
      "Type": "File",
      "FilePath": "localhost.pfx",
      "Password": "MySercurePassword123?"
    }
  },

现在该项目既不能在本地运行,也不能在Azure上运行。Startup.cs中的app.UseIdentityServer();失败,出现以下错误:

Newtonsoft.Json.JsonReaderException:‘遇到意外字符 解析时编号:�。路径"",行%1,位置%1。"

根据Microsoft文档,我的证书应该有效:

用于签署令牌的生产证书。

  • 此证书没有特定要求;它可以是自签名证书,也可以是通过CA颁发机构提供的证书。
  • 可以通过PowerShell或OpenSSL等标准工具生成。
  • 它可以安装到目标计算机上的证书存储中,也可以部署为具有强密码的.pfx文件。

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-5.0#deploy-to-production

如果我这样加载密钥,它会正常工作:

"Key": {
  "Type": "Store",
  "StoreName": "My",
  "StoreLocation": "CurrentUser",
  "Name": "CN=blazortest"
}

推荐答案

我能够通过删除appsettings.Development.json中的IdentityServer条目来修复此问题。

从appsettings.Development.json:

中删除以下行
"IdentityServer": {
     "Key": {
       "Type": "Development"
     }
   } 

这篇关于Blazor-app.UseIdentityServer();带有.pfx密钥文件-解析数字时遇到意外字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆