【问题标题】:Accessing an asp.net api which uses AspNetCore.Authentication.OpenIdConnect from postman从邮递员访问使用 AspNetCore.Authentication.OpenIdConnect 的 asp.net api
【发布时间】:2022-01-20 19:10:59
【问题描述】:
我创建了一个 asp.net 核心 api,它使用 openIdConnect 库使用 Azure AD 对用户进行身份验证,当我从浏览器测试它时它工作正常,但是当我尝试通过生成访问令牌和使用来测试来自邮递员的 api 时它访问api,响应是一个重定向到登录页面,表明我没有被授权,那么我怎样才能从postmanenter image description here访问api
【问题讨论】:
标签:
asp.net
api
authentication
postman
openid-connect
【解决方案1】:
我通过在我的startup.cs 中向ConfigureServices 添加Jwt 承载身份验证解决了这个问题,并用[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + OpenIdConnectDefaults.AuthenticationScheme)] 装饰了控制器,所以如果我试图从浏览器访问api,它将使用openIdConnect 方案,否则它将使用 jwt 方案