c# - 用于 Azure AD 令牌验证的 ASP.NET Core 自定义身份验证筛选器
问题描述
我目前正在开发一个需要使用 Azure AD 令牌的项目,该令牌运行良好。我在 Azure 门户中注册我的应用程序并在我的项目中使用客户端 ID,这与此代码(在 中startup.cs
)一起工作正常:
services.AddMicrosoftIdentityWebApiAuthentication(configuration, "AzureAd");
这些设置在appsettings.json
:
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"TenantId": "35234523452345",
"ClientId": "25234523452345",
"Audience": "api://25234523452345"
},
我只想标记一个 API 调用,但使用上面的代码,它将适用于所有 API。我可以使用将使用 Azure 令牌进行身份验证的自定义筛选器吗?
有人可以帮我提供代码示例吗?
解决方案
An ASP.NET Core web application that authenticates Azure AD users and calls a web API using OAuth 2.0 access tokens.
Here you can find the ASP.NET Core samples about JwtBearer. Here the Azure AD samples demonstrate WebApp calling WebApi (also bearer for the WebAPI, OIDC for the App FrontEnd.
Sample Code: https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect-aspnetcore
Reference SO Thread: Azure AD Authentication in ASP.NET Core 2.2
推荐阅读
- html - 在移动屏幕导航上移动 flexbox 项目
- node.js - 使用 NodeJS Express 为 API 仅输出 JSON 值
- python - Pandas DataFrames to Graph
- javascript - 我正在使用 vanilla js 向 django 发出 ajax 发布请求
- serialization - 使用serde反序列化yaml或json时如何解构枚举?
- python - 如何在输入和输出小部件中启用右键单击以分别在 Tkinter 中粘贴和复制?
- c++ - 为 shared_ptr 创建一个构造函数
- node.js - 通过WebSocket发送数据后如何接收结果
- python - 在准备元数据时,顶点依赖加密给出错误
- node.js - 尝试从 'rxjs/operators' 导入 { map } 时,不支持目录导入解析 ES 模块;