43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using JWT.Algorithms;
|
|||
|
|
using JWT;
|
|||
|
|
using JWT.Serializers;
|
|||
|
|
using JWT.Builder;
|
|||
|
|
|
|||
|
|
namespace ConsoleApplication3
|
|||
|
|
{
|
|||
|
|
class Program
|
|||
|
|
{
|
|||
|
|
static void Main(string[] args)
|
|||
|
|
{
|
|||
|
|
var payload = new Dictionary<string, object>
|
|||
|
|
{
|
|||
|
|
{ "claim1", 0 },
|
|||
|
|
{ "claim2", "claim2-value" }
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
|
|||
|
|
IJsonSerializer serializer = new JsonNetSerializer();
|
|||
|
|
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
|
|||
|
|
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
|
|||
|
|
const string key = "fdfdfd"; // not needed if algorithm is asymmetric
|
|||
|
|
|
|||
|
|
var token = encoder.Encode(payload, key);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
var token111 = JwtBuilder.Create()
|
|||
|
|
.WithAlgorithm(new HMACSHA256Algorithm())
|
|||
|
|
.AddClaim("exp", DateTimeOffset.UtcNow.AddHours(1))
|
|||
|
|
.AddClaim("claim1", 0)
|
|||
|
|
.AddClaim("claim2", "claim2-value")
|
|||
|
|
.Encode();
|
|||
|
|
Console.WriteLine(token);
|
|||
|
|
Console.WriteLine(token);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|