webtokens

JSON Web Token Library

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.1.0
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:27

Authors

  • George Lemon

Installation

nimble install webtokens
choosenim install webtokens
git clone https://github.com/openpeeps/webtokens

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
webtokens - - - - - - -

Dependencies

Package Version Optional
nim >= 2.0.0 No

Source

Repository https://github.com/openpeeps/webtokens
Homepage https://github.com/openpeeps/webtokens
Registry Source nimble_official

README

JWT Logo
👑 Nim lang bindings for LibJWT
JSON Web Token Library

nimble install webtokens

API reference
Github Actions Github Actions

About

This package provides Nim bindings for LibJWT, a C library that supports the following standards JWS, JWE, JWK, JWA and JWTs. It allows you to create, sign, verify, and decode JSON Web Tokens in your Nim applications.

[!NOTE] 👌 Low-level and high-level APIs are provided to work with JWTs, JWKs, and JWS/JWE tokens.

Prerequisites

Check the official LibJWT installation guide

Examples

Here is a simple example demonstrating how to create and sign a JSON Web Token (JWT) using HMAC SHA-256 algorithm with the webtokens Nim package.

Create and Sign a Json Web Token

{.passL:"-L/opt/local/lib -ljwt", passC:"-I /opt/local/include".}

import std/[times, json]
import webtokens

# Generate a JWK Set with one random HMAC (oct) key
let jwksJson = generateJwkSet(1, 32)

let set = loadJwkSetFromJson($jwksJson)
let key = set.findByKid("hmac-key-0")
let alg = parseAlg("HS256")

# Initialize JWT Builder
var builder = newJwtBuilder()
builder.setKey(alg, key)

builder.setHeader("typ", "JWT")
builder.setHeader("kid", key.itemKid())
builder.setIss("example-app")
builder.setSub("user123")

builder.setExpIn(3600) # token expires in 1 hour

# Generate the token
let token = builder.generate()
echo "Generated JWT: ", token

# Now, you can use this token for authentication/authorization
var verifier = newJwtChecker()
verifier.setKey(alg, key)
verifier.setLeeway(JWT_CLAIM_EXP, 5) # small clock skew

if verifier.verify(token):
  echo "Verified OK!"

todo more examples

❤ Contributions & Support

🎩 License

Made by Humans from OpenPeeps.
Copyright OpenPeeps & Contributors — All rights reserved.