Skip to content

A thread-safe luaossl based JWT encoding/decoding module.

License

Notifications You must be signed in to change notification settings

gonapps-org/gonapps-lua-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gonapps-jwt

About

A thread-safe luaossl based JWT encoding/decoding module.
This module is a fork from x25/luajwt.
It is using luaossl instead of LuaCrypto because LuaCrypto is deprecated, not maintained, not thread-safe.
Functions have been slightly changed.

Usage

installation

$ sudo luarocks install gonapps-jwt

example code

local jwt = require "gonapps.jwt"

local key = "example-key"

local payload = {
	iss = "example-issuer",
	nbf = os.time(),
	exp = os.time() + 3600,
}

-- encode
local alg = "HS256" -- (default)
local ok, encodedToken = pcall(jwt.encode, payload, key, alg)
-- encodedToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIx(cutted)...

-- decode (ok is true only if token is valid and successfully decoded)
local ok, decodedToken = pcall(jwt.decode, payload, key, algorithm)
-- decodedToken: { ["iss"] = "example-issuer", ["nbf"] = 1405108000, ["exp"] = 1405181916 }

Algorithms

HMAC

  • HS256 - HMAC using SHA-256 hash algorithm (default)
  • HS384 - HMAC using SHA-384 hash algorithm
  • HS512 - HMAC using SHA-512 hash algorithm

License

MIT

About

A thread-safe luaossl based JWT encoding/decoding module.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages