JwtBuilder 是 DotNetCore.JWT 库中的一个类,用于构建 JSON Web Token (JWT)。这个库支持多种数据类型作为 JWT 的有效载荷(payload)。以下是一些常见的数据类型:
true 或 false 值。以下是一个使用 JwtBuilder 构建 JWT 的示例,其中包含了字符串、整数和布尔值:
using DotNetCore.JWT;
using System;
public class Program
{
    public static void Main()
    {
        var token = JwtBuilder.Create()
            .WithSubject("John Doe")
            .WithIssuer("example.com")
            .WithAudience("example.com")
            .WithExpiration(DateTime.UtcNow.AddMinutes(30))
            .WithClaim("age", 30)
            .WithClaim("isStudent", false)
            .WithClaim("courses", new[] { "math", "history" })
            .Build();
        Console.WriteLine(token);
    }
}
在这个示例中,我们使用 WithClaim 方法添加了三个自定义声明,分别包含字符串、整数和布尔值。这些声明将被添加到 JWT 的有效载荷中。