Created
January 19, 2021 09:17
-
-
Save gtarun/7791fc0bd9fe4a4bbfaf1534ad501836 to your computer and use it in GitHub Desktop.
OG_JWT.md
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
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