Asp.net 如何在controller';中访问当前访问令牌;什么行动?

Asp.net 如何在controller';中访问当前访问令牌;什么行动?,asp.net,.net-core,identityserver4,Asp.net,.net Core,Identityserver4,我有一个带有IdentityServer4的asp.net core 2.1 web API应用程序。我使用client\u凭证flow让客户端访问API 在控制器的操作中(在服务器端),我可以访问当前的客户端id。这可能吗?如何实现?添加必要的using语句: using Microsoft.AspNetCore.Authentication; 然后在操作方法中获取令牌: var accessToken = await AuthenticationHttpContextExtensions.

我有一个带有IdentityServer4的asp.net core 2.1 web API应用程序。我使用
client\u凭证
flow让客户端访问API


在控制器的操作中(在服务器端),我可以访问当前的
客户端id
。这可能吗?如何实现?

添加必要的using语句:

using Microsoft.AspNetCore.Authentication;
然后在操作方法中获取令牌:

var accessToken = await AuthenticationHttpContextExtensions.GetTokenAsync(
    HttpContext, OpenIdConnectParameterNames.AccessToken);

我还发现,我可以通过访问
User.Claims
并通过
JwtClaimsType