从邮递员访问使用 AspNetCore.Authentication.OpenIdConnect 的 asp.net api

Accessing an asp.net api which uses AspNetCore.Authentication.OpenIdConnect from postman

我创建了一个 asp.net 核心 api,它使用 openIdConnect 库对使用 Azure AD 的用户进行身份验证,当我从浏览器测试它时它工作正常,但当我尝试测试 api 来自 post 人,通过生成访问令牌并使用它来访问 api,响应是重定向到登录页面,表明我未经授权,所以我如何访问 api 来自 post人enter image description here

我通过在我的 startup.cs 中向 ConfigureServices 添加 Jwt 承载身份验证解决了这个问题,并用 [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + OpenIdConnectDefaults.AuthenticationScheme)] 装饰了控制器,所以如果我试图访问 api在浏览器中它将使用 openIdConnect 方案,否则它将使用 jwt 方案