如何在 c# webapi 中使用 IdentityModel.OidcClient 来验证和验证从支持 openid 连接的活动目录服务生成的令牌?

How can I use IdentityModel.OidcClient in a c# webapi to verify and validate token generated from active directory service supporting openid connect?

我在 C# 中有一个 Webapi 和一个前端 angular 应用程序。 angular 应用程序正在调用 Active Directory 服务(例如 Azure 广告)以获取访问令牌。在随后的 webapi 调用中,web api 应用程序需要验证访问令牌。

我的网站api 到目前为止一直在使用 Microsoft.Owin.Security jwt 令牌验证。我想用 IdentityModel.OidcClient 替换 Microsoft.Owin.Security (因为这是经过认证的 c# openid 连接库)。请帮助我了解如何使用 OidcClient 框架来验证令牌。

要验证令牌,您不应使用 IdentityModel.OidcClient,而应使用 Microsoft.AspNetCore.Authentication.JwtBearer Nuget 包来正确验证 API.

中的 JWT 令牌