Oauth 2.0 处理消息时发生异常。System.InvalidOperationException:IDX20803:无法从以下位置获取配置:';[PII是隐藏的

Oauth 2.0 处理消息时发生异常。System.InvalidOperationException:IDX20803:无法从以下位置获取配置:';[PII是隐藏的,oauth-2.0,blazor,Oauth 2.0,Blazor,我正在使用Auth2.com保护我的Blazor WebAssembly应用程序的安全,我正在使用命令行运行该程序。我可以成功完成所有步骤,并且可以安装Blazor应用程序。但是,对于最后一步,我从命令行收到此错误 Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3] Exception occurred while processing message. System.InvalidOperationEx

我正在使用Auth2.com保护我的Blazor WebAssembly应用程序的安全,我正在使用命令行运行该程序。我可以成功完成所有步骤,并且可以安装Blazor应用程序。但是,对于最后一步,我从命令行收到此错误

Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
      Exception occurred while processing message. System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.  ---> System.ArgumentException: IDX20108: The address specified '[PII is hidden. For more details, see https://aka.ms/IdentityModel/PII.]' is not valid as per HTTPS scheme. Please specify an https address for security reasons. If you want to test with http address, set the RequireHttps property  on IDocumentRetriever to false. (Parameter 'address')
在我的浏览器控制台中,出现以下错误:

这是使用API的QuizViewer.razor

@page "/quizViewer"
@attribute [Authorize]
@using QuizManagerClientHosted.Shared
@using System.Net.Http.Json

@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using System.Net.Http.Headers

@inject HttpClient Http
@inject IAccessTokenProvider TokenProvider 

<h1>Take your quiz!</h1>
<p>Your current score is @currentScore</p>

@if (quiz == null)
{
    <p><em>Loading...</em></p>
}
else
{
    int quizIndex = 0;
    @foreach (var quizItem in quiz)
    {
        <section>
            <h3>@quizItem.Question</h3>
            <div class="form-check">
                @{
                    int choiceIndex = 0;
                    quizScores.Add(0);
                }
                @foreach (var choice in quizItem.Choices)
                {
                    int currentQuizIndex = quizIndex;
                    <input class="form-check-input" type="radio" name="@quizIndex" value="@choiceIndex" @onchange="@((eventArgs) => UpdateScore(Convert.ToInt32(eventArgs.Value), currentQuizIndex))" />@choice<br>

                    choiceIndex++;
                }
            </div>
        </section>

        quizIndex++;
    }
}


@code {
    List<QuizItem> quiz;
    List<int> quizScores = new List<int>();
    int currentScore = 0;

    protected override async Task OnInitializedAsync()
    {

        using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, "quiz"))
        {
            var tokenResult = await TokenProvider.RequestAccessToken();

            if (tokenResult.TryGetToken(out var token))
            {
                requestMessage.Headers.Authorization =
                  new AuthenticationHeaderValue("Bearer", token.Value);
                var response = await Http.SendAsync(requestMessage);
                quiz = await response.Content.ReadFromJsonAsync<List<QuizItem>>();
            }
        }

    }

    void UpdateScore(int chosenAnswerIndex, int quizIndex)
    {
        var quizItem = quiz[quizIndex];

        if (chosenAnswerIndex == quizItem.AnswerIndex)
        {
            quizScores[quizIndex] = quizItem.Score;
        }
        else
        {
            quizScores[quizIndex] = 0;
        }
        currentScore = quizScores.Sum();
    }
}

如何修复此问题?我配置的哪个部分错误?

Auth0中的每个帐户都有一个查找终结点,您可以通过转到Auth0应用程序的设置来找到它,然后在“高级设置”下找到“终结点”选项卡

在那里,您将找到您的OpenID配置URL


您可以从浏览器访问Auth0发现文档吗?我如何访问发现文档?是的,我可以从浏览器访问该OpenId URL。还需要检查什么?错误消息抱怨HTTPS丢失,您是否已将此发现端点添加到API中(“测验端点”)?您能否验证接收令牌的API是否实际获得了发现文档?使用Fiddler之类的工具并进行调查…可以随意将这些请求添加到您的问题中。API是如何保护的?也可以随意在此处添加启动类。
您是否已将此发现端点添加到您的API(测试端点)中?您能验证接收令牌的API是否实际获得了发现文档吗?
这意味着什么?对于源代码,我已在原始帖子中添加了。谢谢。我意识到我犯的错误是在注册API时没有输入正确的
唯一标识符
,这会影响最后一步,即输入相同的v在
默认观众中的价值
真棒!很高兴你发现了问题!
using QuizManagerClientHosted.Shared;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

namespace QuizManagerClientHosted.Server.Controllers
{
    [ApiController]
    [Route("[controller]")]
    [Authorize]
    public class QuizController : ControllerBase
    {
        private static readonly List<QuizItem> Quiz = new List<QuizItem> {
            new QuizItem
                {
                    Question = "Which of the following is the name of a Leonardo da Vinci's masterpiece?",
                    Choices = new List<string> {"Sunflowers", "Mona Lisa", "The Kiss"},
                    AnswerIndex = 1,
                    Score = 3
                },
                new QuizItem
                {
                    Question = "Which of the following novels was written by Miguel de Cervantes?",
                    Choices = new List<string> {"The Ingenious Gentleman Don Quixote of La Mancia", "The Life of Gargantua and of Pantagruel", "One Hundred Years of Solitude"},
                    AnswerIndex = 0,
                    Score = 5
                }
            };

        [HttpGet]
        public List<QuizItem> Get()
        {
            return Quiz;
        }
    }
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Authentication.JwtBearer;

namespace QuizManagerClientHosted.Server
{
  public class Startup
  {
    public Startup(IConfiguration configuration)
    {
      Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
      services.AddAuthentication(options =>
      {
        options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
      }).AddJwtBearer(options =>
      {
        options.Authority = Configuration["Auth0:Authority"];
        options.Audience = Configuration["Auth0:ApiIdentifier"];
      });

      services.AddControllersWithViews();
      services.AddRazorPages();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
        app.UseWebAssemblyDebugging();
      }
      else
      {
        app.UseExceptionHandler("/Error");
    
        app.UseHsts();
      }

      app.UseHttpsRedirection();
      app.UseBlazorFrameworkFiles();
      app.UseStaticFiles();

      app.UseRouting();

      app.UseAuthentication();
      app.UseAuthorization();

      app.UseEndpoints(endpoints =>
      {
        endpoints.MapRazorPages();
        endpoints.MapControllers();
        endpoints.MapFallbackToFile("index.html");
      });
    }
  }
}