Skip to content

Instantly share code, notes, and snippets.

@kasramp

kasramp/index.js Secret

Created June 3, 2020 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasramp/c1cc17942a5791cfc51f9b7d4a70e856 to your computer and use it in GitHub Desktop.
Save kasramp/c1cc17942a5791cfc51f9b7d4a70e856 to your computer and use it in GitHub Desktop.
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