IDX:20803无法从…获得配置-Web API

问题描述 投票:0回答:1

[您好,我正在尝试使用JWT令牌测试一个简单的WebApi应用程序。主要,我按照示例here

我正在使用https。

暂时不使用授权。问题是,如果在邮递员中选择“从父​​项继承身份验证”,一切都会正常。

一旦我将选项更改为“ BearerToken”,并尝试输入收到的JSONWebToken,它就会给我

System.InvalidOperationException:IDX20803:无法从'https://localhost:44387/api/.well-known/openid-configuration'获取配置。---> System.IO.IOException:IDX20804:无法从“ https://localhost:44387/api/.well-known/openid-configuration”检索文档。---> System.Net.Http.HttpRequestException:响应状态代码未指示成功:404(未找到)。在System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()在Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(字符串地址,CancellationToken取消)---内部异常堆栈跟踪的结尾---在Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(字符串地址,CancellationToken取消)

[请注意,我在这里没有使用IdentityServer

中间件,而且在浏览器上,我也无法浏览到https://localhost:44387/api/.well-known/openid-configuration

我不确定此“ openid-configuration”

的位置,特别是当我未在aspnet Core 3.0 Web APi应用程序中明确使用它时?这是我的代码。.

Startup.cs

public void ConfigureServices(IServiceCollection services)
    { 
     //extra code removed for brevity
     //Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.Authority = "https://localhost:44387/api";
                options.Audience = "JWT:Issuer";
                options.TokenValidationParameters.ValidateLifetime = true;
                options.TokenValidationParameters.ClockSkew = TimeSpan.FromMinutes(5);
                options.RequireHttpsMetadata = false;

            });
 }

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
       if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            //to send HTTP Strict Transport Security Protocol (HSTS) headers to clients.
            app.UseHsts();
        }

        //to redirect HTTP requests to HTTPS.
        app.UseHttpsRedirection();

        app.UseAuthentication();

        app.UseRouting();





        app.UseEndpoints(endpoints =>
        {

            endpoints.MapControllers();

            endpoints.MapRazorPages();
        });
    }

代替https://localhost:44387/api

,我也尝试了https://localhost:44387/https://localhost,但是没有运气。.我主要是想了解为什么我不使用openid时会出现openid一切。一切都在我的本地计算机上,并且我正在使用IISExpress。

我也尝试过通过修复IISExpress来删除和重新创建本地SSL证书。

任何线索都会有所帮助。

[您好,我正在尝试使用JWT令牌测试一个简单的WebApi应用程序。主要地,我在这里使用https跟随示例。暂时不使用授权。问题是...

c# asp.net-core asp.net-web-api jwt
1个回答
0
投票

在您设置为AddJwtBearer时,由于您设置了Authority,它将与OIDC元数据文档联系,该文件用于在验证由令牌服务的私钥发行的jwt令牌时获取服务的公共签名密钥。

© www.soinside.com 2019 - 2024. All rights reserved.