identityserver4。如何从登录页面中创建访问令牌?

identityserver4。如何从登录页面中创建访问令牌?,identityserver4,Identityserver4,我已经使用IdentityServer 4和我自己的登录页面创建了一个IdentityServer应用程序。当用户登录(或由于凭据无效而无法登录)时,我需要创建该交互的审核日志记录。我的系统有一个单独的web服务来处理审计日志记录。为了从IdentityServer实例中的登录页面调用该服务,我需要一个访问令牌。IdentityServer4中是否有一个类/方法,我可以调用它来创建访问令牌?在我的应用程序实例中,为了获取令牌而对令牌端点进行web服务调用似乎有些过分 也就是说,我的Identit

我已经使用IdentityServer 4和我自己的登录页面创建了一个IdentityServer应用程序。当用户登录(或由于凭据无效而无法登录)时,我需要创建该交互的审核日志记录。我的系统有一个单独的web服务来处理审计日志记录。为了从IdentityServer实例中的登录页面调用该服务,我需要一个访问令牌。IdentityServer4中是否有一个类/方法,我可以调用它来创建访问令牌?在我的应用程序实例中,为了获取令牌而对令牌端点进行web服务调用似乎有些过分

也就是说,我的IdentityServer应用程序需要能够为外部客户端创建访问令牌,但它也需要能够创建它们供自己使用,以便能够调用外部服务,如审计日志记录


还是我的看法完全错了?

创建访问令牌的类是
DefaultTokenService
,它的可访问性级别为
public

有关方法如下:

public virtual async Task<Token> CreateAccessTokenAsync(TokenCreationRequest request)

只需将“IdentityServerTools”注入到您的类中,它就有了必要的API

再一次。没有文档,也没有提供示例。因为您在任何地方都提出了很好的要求-再次感谢您。顺便说一句,在答案被编辑之前,我无法投票。一旦成功了,我会的。
public AccountController(
    IIdentityServerInteractionService interaction,
    IClientStore clientStore,
    IHttpContextAccessor httpContextAccessor,
    ITokenCreationService tokenCreationService,
    TestUserStore users = null)
{
    _users = users ?? new TestUserStore(Config.Users);
    _interaction = interaction;
    _account = new AccountService(interaction, httpContextAccessor, clientStore);
    _identityServerTools = new IdentityServerTools(httpContextAccessor, tokenCreationService);
}