c# - 带有 ASP.NET WEB API 2 的 IdenityServer3 给出授权被拒绝消息
问题描述
作为 API 验证的一部分,我们使用IdenityServer4 NuGet 包和网络核心创建了一个身份服务器。我们现有的 API 在ASP.NET WEB API 2中运行。由于 IdenityServer4 NuGet 包不能与 WEB API 2 压缩,我们使用IdenityServer3 NuGet 包来验证令牌。我们能够从 Idenityserver 获取令牌,但是当我们将此令牌传递给 API(在标头中)时,它会显示 - “此请求的授权已被拒绝。” . 我在这里做错了什么?
启动类(在 WEB API 中)
[assembly: OwinStartup(typeof(WebApplication2.Startup))]
namespace WebApplication2
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44385/",
RequiredScopes = new[] { "offline_access openid api/Default" }
});
}
}
}
URL - https://localhost:44385/是我的 IdenityServer 运行的地方。
我的 Controller 类如下所示
[Authorize]
public class DefaultController : ApiController
{
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
我的 Postman 请求关于我如何调用我的 API 的屏幕截图
解决方案
推荐阅读
- excel - VBA根据单元格值中提到的范围将单个excel表中的多个范围保存为pdf
- python - 如何在运行 exe 遇到错误时整理所有必要的 Pyinstaller 隐藏导入,而无需进行故障排除
- javascript - Angular typescript object.assign 不起作用(它返回错误无法读取 null 的“长度”)
- python - 绑定滑块以适应音频位置而不会导致性能下降
- mongodb - 使用 mongoDB 和 express.js 实现分页 REST API
- fortran - 临时数组创建和例程 GEMM
- coq - `Set` 类型的具体例子是什么,`Set` 的含义是什么?
- javascript - Angular 9按钮单击多次触发
- visual-studio-code - 信任作者对话框中的复选框和是选项有什么区别?
- linux - 要为 arm(多功能板)编译和构建 linux-5.8.10 映像并使用 Qemu 模拟它: