a Base64 encoded JSON object
with a cryptographic signature
Usable in
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
{
"alg": "HS256",
"typ": "JWT"
}
{
"sub": "1234567890",
"name": "John Doe",
"iat": 1516239022
}
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ
SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
const data =
const key = crypto.subtle.importKey("raw", key,
{ name: "HMAC", hash: { name: "SHA-" + this.length } },
false, [ "sign", "verify" ])
const signature = await crypto.subtle.sign("HMAC", await key, data)
const header = {
alg: "HS256",
typ: "JWT"
}
const payload = {
sub: "1234567890",
name: "John Doe",
iat: 1516239022
}
const data = Base64.encode(new TextEncoder().encode(JSON.stringify(header))) + "." +
Base64.encode(new TextEncoder().encode(JSON.stringify(payload)))
const key = crypto.subtle.importKey("raw", key,
{ name: "HMAC", hash: { name: "SHA-" + this.length } }, false,[ "sign", "verify" ])
const signature = await crypto.subtle.sign("HMAC", await key, data)
const token = data + "." + signature
{
"typ":"JWT",
"alg":"HS256"
}
{
"typ":"JWT",
"alg":"RS256"
}
algorithms:
bit lengths:
Registered Claims:
github.com/payfunc/authly · MIT license
import * as authly from "authly"
const algorithm = authly.Algorithm.HS256(process.env.apiKeySecret)
const verifier = authly.Verifier.create("audience", algorithm)
const issuer = authly.Issuer.create("issuer", algorithm)
const token = await issuer.issue({
sub: "1234567890",
name: "John Doe",
admin: true,
iat: 1516239022,
aud: "audience"
})
const payload = await verifier.verify(token)
npm install -S authly
import * as authly from "authly"
const algorithm = authly.Algorithm.HS256(process.env.apiKeySecret)
const verifier = authly.Verifier.create("audience", algorithm).add(process.env.propertySecret, "property0", "property1")
const issuer = authly.Issuer.create("issuer", algorithm).add(process.env.propertySecret, "property0", "property2")
const token = await issuer.issue(payload)
const payload = await verifier.verify(token)
const secret = this.secret + payload.sub + payload.iat + property.join(".")
const key = new Uint8Array(await crypto.subtle.digest("SHA-512", new TextEncoder().encode(secret)))
const data = preprocess(payload[property[0]])
const processed = new Uint8Array(data.length)
for (let index = 0; index < data.length; index++)
processed[index] = data[index] ^ key[index]
result = postprocess(processed)
property must be shorter then 512 bits