【问题标题】:IOException: IDX20807: Unable to retrieve document from: 'System.String'. HttpResponseMessage:IOException:IDX20807:无法从“System.String”检索文档。 HttpResponse 消息:
【发布时间】:2021-06-26 04:05:55
【问题描述】:

我正在使用 Asp.Net Core 3.1 并通过 Challenge 方法,调用外部端点进行身份验证

public async Task<IActionResult> Challenge(string provider, string returnUrl,string userName)
        {
           
                var props = new AuthenticationProperties
                {
                    RedirectUri = Url.Action(nameof(Callback)),
                    Items =
                    {
                        { "returnUrl", returnUrl },
                        { "scheme", provider },
                    },
                    Parameters =
                    {
                        { OidcConstants.AuthorizeRequest.LoginHint, userName }
                    }
                };

                var result = Challenge(props, provider);
                return result;
            }

错误:

An unhandled exception occurred while processing the request.
IOException: IDX20807: Unable to retrieve document from: 'System.String'. HttpResponseMessage: 'System.Net.Http.HttpResponseMessage', HttpResponseMessage.Content: 'System.String'.
Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, CancellationToken cancel)

InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'.
Microsoft.IdentityModel.Protocols.ConfigurationManager<T>.GetConfigurationAsync(CancellationToken cancel)

感谢,任何快速响应。

【问题讨论】:

  • 你解决了吗@Mahendra?

标签: asp.net exception


【解决方案1】:

也许这对你有帮助:我使用了来自 https://dev.to/moe23/asp-net-core-5-rest-api-authentication-with-jwt-step-by-step-140d 的脚手架示例

在此示例中,引用了 Nuget 包 System.IdentityModel.Tokens.Jwt。 我删除了它,因为我不需要它,并且错误消失了

【讨论】:

    【解决方案2】:

    当我在 Visual Studio 2019 中创建新的 .NET 5 项目时遇到此异常。

    IOException:IDX20807:无法从以下位置检索文档: '系统.字符串'。 HttpResponse 消息: 'System.Net.Http.HttpResponseMessage',HttpResponseMessage.Content: '系统.字符串'。 Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(字符串 地址,CancellationToken 取消) Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(字符串 地址,IDocumentRetriever 检索器,CancellationToken 取消) Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken 取消)

    在启动应用程序之前出现此错误:

    必需的组件 - dotnet msidentity tool

    您可以在连接的服务 - 服务依赖项中修复此问题,并通过按配置来设置 Microsoft 身份平台。

    对我来说,它就像这样卡住了,但什么也没发生:

    appsettings.json 然后我找到了以下代码:

    /*
    The following identity settings need to be configured
    before the project can be successfully executed.
    For more info see https://aka.ms/dotnet-template-ms-identity-platform 
    */
    

    访问了https://aka.ms/dotnet-template-ms-identity-platform 并改用了工具msidentity-app-sync。首先安装它,然后验证我是否安装了该工具。

    dotnet tool install -g msidentity-app-sync
    dotnet tool list -g
    

    然后在项目文件夹中运行msidentity-app-sync。将在Azure Active Directory 中创建一个新的App registrations,该项目现在可以运行了。

    如果您希望像这样使用现有应用程序,您也可以自己指定租户和客户:

    msidentity-app-sync --tenant-id <tenant-id> --username <username> --client-id <client-id>
    

    【讨论】:

      【解决方案3】:

      不确定这有多大关系,但有人可能会发现它对处理此异常很有用。

      我正在使用 Asp.Net Core 3.1,尝试实现 JWT 身份验证。设置权限后,我开始收到类似的error

      Fix 的问题是设置 'ValidIssuer' 参数,而不是设置权限。

      【讨论】:

        【解决方案4】:

        也证实了杜桑的回答。来自https://devblogs.microsoft.com/dotnet/jwt-validation-and-authorization-in-asp-net-core/

        Authority 是颁发令牌的身份验证服务器的地址。 JWT 不记名身份验证中间件将使用此 URI 来查找和检索可用于验证令牌签名的公钥。它还将确认令牌中的 iss 参数与此 URI 匹配。

        我没有使用公共令牌颁发身份验证服务器。

        【讨论】:

        猜你喜欢
        • 2022-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-03
        • 2019-09-29
        • 2017-08-15
        相关资源
        最近更新 更多