tsndr / cloudflare-worker-jwt

A lightweight JWT implementation with ZERO dependencies for Cloudflare Workers.
MIT License
649 stars 51 forks source link

Add parameters in header? #37

Closed bryanlatten closed 1 year ago

bryanlatten commented 1 year ago

Fantastic library, thanks for sharing!

Was curious if it were possible to add values into the JOSE header, similar to https://github.com/panva/jose/blob/73da49330f940133ce257724a571fa29c0f0b98e/docs/interfaces/types.JWSHeaderParameters.md

I'm specifically looking to add a certificate identifier (x5t / x5u), which will make rotation that much easier.

Thank you!

tsndr commented 1 year ago

Hi @bryanlatten,

thanks for using my library.

You can already do that:

import { sign } from '@tsndr/cloudflare-worker-jwt'

const payload = { sub: 'user-id' }
const secret = 'super_secret_secret'
const options = {
    header: {
        typ: 'JWT',
        x5t: '...',
        x5u: '...'
    }
}

const token = await sign(payload, secret, options)

token

Screenshot 2023-06-28 at 4 53 16 PM

They're just not fully typed: https://github.com/tsndr/cloudflare-worker-jwt/blob/76b7fcef2707225c9214fcba0c4e8d6498039daa/src/index.ts#L21-L30

Hope that helped and I will add to my TODOs to complete the types.

bryanlatten commented 1 year ago

Thanks for the fast response - makes sense and appreciated!