-
-
Save kasramp/c1cc17942a5791cfc51f9b7d4a70e856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { validateJwt } from "https://deno.land/x/djwt/validate.ts"; | |
import { makeJwt, setExpiration } from "https://deno.land/x/djwt/create.ts"; | |
const expirationMinute = 10; | |
const key = "dummy_key" | |
const getTokenExpirationAsMilliseconds = () => { | |
return new Date().getTime() + expirationMinute * 60 * 1000; | |
} | |
const payload = { | |
iss: "dummy_issuer", | |
exp: setExpiration(getTokenExpirationAsMilliseconds()), | |
} | |
const header = { | |
alg: "HS256", | |
typ: "JWT", | |
} | |
const generateToken = () => { | |
return makeJwt({ key, header, payload }) | |
} | |
const validateToken = (token) => { | |
return validateJwt(token, key, { isThrowing: false }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment