代码之家  ›  专栏  ›  技术社区  ›  johnny 5

Identity Server 4向生成的令牌添加声明

  •  1
  • johnny 5  · 技术社区  · 7 年前

    我正在使用IdentityServerTools生成令牌:

    private async Task<string> CreatePaymentsTokenAsync()
    {
        var tokenLifeTime = 3600;
        var scopes = new[] { CoinbaseAuthConsts.PaymentScope };
        // Use in-built Identity Server tools to issue JWT
        var token = await _identityServerTools.IssueClientJwtAsync(
                CoinbaseAuthConsts.AuthorityClientId, 
                tokenLifeTime, scopes, new[] { "AstootApi" });
        return token;
    }
    

    如何向令牌添加声明?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Camilo Terevinto Chase R Lewis    7 年前

    IssueClientJwtAsync is

    如果希望对生成的令牌进行更精确的控制,请使用 IssueJwtAsync

    Task<string> IssueJwtAsync(int lifetime, IEnumerable<Claim> claims)
    // or
    Task<string> IssueJwtAsync(int lifetime, string issuer, IEnumerable<Claim> claims)
    

    您可能需要检查源代码中的 IssueClientJwtAsync 查看如何完成内部调用。