Skip to content

Instantly share code, notes, and snippets.

@gtarun
Created January 19, 2021 09:17
Show Gist options
  • Save gtarun/7791fc0bd9fe4a4bbfaf1534ad501836 to your computer and use it in GitHub Desktop.
Save gtarun/7791fc0bd9fe4a4bbfaf1534ad501836 to your computer and use it in GitHub Desktop.
OG_JWT.md
const TOKEN_SECRET="7bc78545b1a3923cc1e1e19523fd5c3f20b409509";
const jwt = require("jsonwebtoken");
const request = require("request");
let usernam = "gtarun";
let token = jwt.sign(username, TOKEN_SECRET, { expiresIn: '1800s' });
// Make an HTTP POST request
request(options, function(err, res, body) {
let json = JSON.parse(body);
console.log(json);
});
const resp = await request({
method: "POST",
url: `https://jsonplaceholder.typicode.com/posts`,
headers: {
"Content-Type": "application/json",
"Authorization": "JWT " + token, // JWT token
},
data: {
name: "Luke",
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment