cdbattags / lua-resty-jwt

JWT For The Great Openresty
Apache License 2.0
146 stars 44 forks source link

The token is not identical due to table not being ordered #60

Open odiferousmint opened 1 year ago

odiferousmint commented 1 year ago

Hey. Due to the table header not being ordered, I get two different tokens (randomly). Both are correct, but it is unacceptable in many cases to not have only one token.

local function generateToken(payload)
  local token = jwt:sign(secret, {
    header = { typ = "JWT", alg = "HS512" },
    payload = payload,
    exp = ngx.time() + tokenExp
  })
  return token
end

The issue is that the header table might end up being { typ = "JWT", alg = "HS512" } and at other times { alg = "HS512", typ = "JWT" }, and thus resulting in a completely different token.

Do any of you know if there is a workaround for it?