repl.it
@bbenefield89/

Sign/Verify RS256 Tokens w/ jsonwebtoken

Express

No description

fork
loading
Files
  • index.js
  • db.js
  • rsa_keys.json
  • Packager files
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const express = require("express");
const jwt = require("jsonwebtoken");

const app = express();
// grab private and public keys
const { privateKey, publicKey } = require('./rsa_keys.json')

app.get("/", (req, res) => {
  // sign token using RS256
  const token = jwt.sign(
    {
      username: "bbenefield89"
    },
    privateKey.join('\n'),
    {
      algorithm: "RS256",
      expiresIn: "1m",
      issuer: "https://example.com"
    }
  );

  const userInformation = jwt.verify(
    token,
    publicKey.join('\n'),
    { algorithms: ['RS256'] }
  )

  res.send(userInformation)
});

app.listen(8080, console.log("Server Listening"));
?