pilcrowonpaper / oslo

A collection of auth-related utilities
https://oslo.js.org
MIT License
1.06k stars 35 forks source link

Create key from string #76

Closed david-plugge closed 4 months ago

david-plugge commented 4 months ago

Is there a way to create a key from a random string for signing and verifying jwts using oslo? If not, how to do it?

My goal is to be able to specify a secret as an env variable that is used for handling jwts.

david-plugge commented 4 months ago

It was too early in the morning...

practicatto commented 3 months ago

@david-plugge did you solve this? how did you that?

david-plugge commented 3 months ago

Simply use TextEncoder

const JWT_KEY = new TextEncoder().encode(env.MAGIC_LINK_TOKEN_SECRET);

await createJWT(
    algorithm,
    JWT_KEY,
    {},
    {
        subject: email,
        expiresIn: new TimeSpan(10, 'm')
    }
);
practicatto commented 3 months ago

Yes silly me, thanks :)