JSON Web Token library to generate, parse, sign, and verify JWTs.
Go to file
Andrew Lalis 9cf62e4d36 Add more docs, more cleanup. 2025-07-30 21:18:08 -04:00
source/jwt4d Add more docs, more cleanup. 2025-07-30 21:18:08 -04:00
.gitignore Initial implementation. 2025-07-29 20:29:19 -04:00
LICENSE Initial commit 2025-07-29 23:10:16 +00:00
README.md Add more docs, more cleanup. 2025-07-30 21:18:08 -04:00
dub.json Initial implementation. 2025-07-29 20:29:19 -04:00
dub.selections.json Initial implementation. 2025-07-29 20:29:19 -04:00

README.md

JWT4D

A JSON Web Token library to generate, parse, sign, and verify JWTs.

Currently, only the "HS256" algorithm is supported.

Example: Create a JWT

import jwt4d;
import std.datetime; // To set expiration in duration.
import std.json; // To add a custom claim value.
import std.stdio;

const string MY_SECRET = "this is a secret!";

JwtClaims claims = JwtClaims()
    .issuer("my.webpage.com")
    .subject("user123")
    .issuedAtNow()
    .expiresIn(minutes(30))
    .customClaim("role", JSONValue("admin"));
string token = writeJwt(claims, MY_SECRET);
writeln(token);

Example: Read a JWT

import jwt4d;
import std.stdio;

const string MY_SECRET = "this is a secret!";

string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTM5MjYzMjAsImlhdCI6MTc1MzkyNDUyMCwiaXNzIjoibXkud2VicGFnZS5jb20iLCJyb2xlIjoiYWRtaW4iLCJzdWIiOiJ1c2VyMTIzIn0.n5X2giJ3S5T3wrW4C0qlZrShr2ZwPiWIu6FxUzQ3K9s";

JwtClaims claims = readJwt(token, MY_SECRET);
writeln(claims.toJson());