Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a bearer token with js (node.js)?

After searching the web, I found there are many posts and modules help parse bearer token, but I didn't found any help create one.

How should I properly generate a bearer token in node.js server?

like image 390
Yao Zhao Avatar asked Feb 12 '17 16:02

Yao Zhao


1 Answers

You can use jwt.io token. To generate a token check out jsonwebtoken module.

You can generate a token like this:

let token = jwt.sign({
  exp: Math.floor(Date.now() / 1000) + (60 * 60),
  data: 'foobar'
}, 'secret');

There are plenty other examples in the docs.

like image 152
Antonio Narkevich Avatar answered Nov 22 '22 13:11

Antonio Narkevich