我正在使用 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;
}
Run Code Online (Sandbox Code Playgroud)
错误:
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)
Run Code Online (Sandbox Code Playgroud)
感谢,任何快速反应。
当我在 Visual Studio 2019 中创建新的 .NET 5 项目时出现此异常。
IOException:IDX20807:无法从“System.String”检索文档。HttpResponseMessage:'System.Net.Http.HttpResponseMessage',HttpResponseMessage.Content:'System.String'。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
*/
Run Code Online (Sandbox Code Playgroud)
访问了https://aka.ms/dotnet-template-ms-identity-platform并使用了该工具msidentity-app-sync。首先安装它,然后验证我是否安装了该工具。
dotnet tool install -g msidentity-app-sync
dotnet tool list -g
Run Code Online (Sandbox Code Playgroud)
然后msidentity-app-sync在项目文件夹中运行。App registrations将创建一个新Azure Active Directory项目,并且该项目现在可以运行。
如果您想使用现有的应用程序,您还可以自己指定租户和客户,如下所示:
msidentity-app-sync --tenant-id <tenant-id> --username <username> --client-id <client-id>
Run Code Online (Sandbox Code Playgroud)
也许这对您有帮助:我使用了https://dev.to/moe23/asp-net-core-5-rest-api-authentication-with-jwt-step-by-step-140d中的支架示例
在此示例中,引用了 Nuget 包 System.IdentityModel.Tokens.Jwt。我删除了它,因为我不需要它,错误就消失了
| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |