第45章 工具 - Identity Server 4 中文文档(v1.0.0)

IdentityServerTools是为IdentityServer编写扩展代码时,你可能需要有效的内部工具的集合。要使用它,请将其注入代码,例如控制器:

public MyController(IdentityServerTools tools)
{
    _tools = tools;
}

IssueJwtAsync方法允许使用IdentityServer令牌创建引擎创建JWT令牌。这IssueClientJwtAsync是为服务器到服务器通信创建令牌的简单版本(例如,当您必须从代码中调用受IdentityServer保护的API时):

public async Task<IActionResult> MyAction()
{
    var token = await _tools.IssueClientJwtAsync(
        clientId: "client_id",
        lifetime: 3600,
        audiences: new[] { "backend.api" });

    // more code
}

github地址

posted @ 2019-04-28 22:15  ThinkJay  阅读(280)  评论(0编辑  收藏  举报