express-jwt

Super test, test secure REST API

谁都会走 提交于 2019-12-03 00:27:47
I am writing integration test for a REST API protected by a jwt . One API operation POST /user/token is returning a jwt given a username and a password and this token is then used for a list of operations such as: GET /user/:id Where the route is using jwt({secret: secret.secretToken}) , so the token is included into the http header Authorization . When testing with super test, I can have nested testing but I want to first get the token, then use this token for other operation testing. POST /user/token => 12345 GET /user/:id, `Authorization Bearer 12345` GET /user/:foo, `Authorization Bearer

How to send a token with an AJAX request from jQuery

为君一笑 提交于 2019-12-02 18:00:06
I use express-jwt and create my token via jQuery and save it in my localStorage with: $.ajax({ url: "http://localhost:8080/login", type: 'POST', data: formData, error : function(err) { console.log('Error!', err) }, success: function(data) { console.log('Success!') localStorage.setItem('token', data.id_token); } }); I have a protected route in my backend like: app.get('/upload',jwt({secret: config.secret}), function(req, res) { res.sendFile(path.join(__dirname + '/upload.html')); }); How can I send the token from localStorage with the request header? You can set the headers in a $.ajax request:

Node js, JWT token and logic behind

爷,独闯天下 提交于 2019-11-30 03:58:45
I'm using the JWT to protect node js urls https://github.com/auth0/express-jwt To create a JWT token user session i simply do: -> auth/signup -> jwt.sign(user_profile,secret,expireInMinutes:{900000000 /*almost never expires*/}); OR in case of login call -> auth/login -> jwt.sign(user_profile,secret,expireInMinutes:{900000000 /*almost never expires*/}); Every time a protected url is called i check for req.user that is set up automatically by the JWT middleware. Now I'm wondering: 1 - where does JWT tokens are stored when calling sign() ? 2 - do i have to verify() the token every time a

JSON Web Token (JWT) benefits over a database session token

狂风中的少年 提交于 2019-11-29 19:11:58
With a database session token system I could have a user login with a username/password, the server could generate a token (a uuid for example) and store it in the database and return that token to the client. Every request from thereon would include the token and the server would look up whether the token is valid and what user it belongs to. Using JWT there would be no need to save anything to the database with respect to session/tokens thanks to the combination of the secret key kept on the server and the signed token the client keeps and sends with every request. This is good but besides

Node js, JWT token and logic behind

喜夏-厌秋 提交于 2019-11-29 01:00:37
问题 I'm using the JWT to protect node js urls https://github.com/auth0/express-jwt To create a JWT token user session i simply do: -> auth/signup -> jwt.sign(user_profile,secret,expireInMinutes:{900000000 /*almost never expires*/}); OR in case of login call -> auth/login -> jwt.sign(user_profile,secret,expireInMinutes:{900000000 /*almost never expires*/}); Every time a protected url is called i check for req.user that is set up automatically by the JWT middleware. Now I'm wondering: 1 - where

implementing refresh-tokens with angular and express-jwt

元气小坏坏 提交于 2019-11-28 17:40:47
I want to implement the Sliding expiration concept with json web tokens using angular, nodejs and express-jwt. I'm a little confused on how to do this, and am struggling to find any example of refresh tokens or and other material relating to sessions with these technologies/frameworks. A few options I was thinking of were Generating a new token with each request after the initial login Keeping track of issued token on the server side along But I'm honestly not sure, please help almoraleslopez I managed to implement this scenario. What I've done... On the server: -Enable an API endpoint for

Any complete example for express-jwt? [closed]

删除回忆录丶 提交于 2019-11-28 08:37:30
问题 I want to use express-jwt in my express node application but I can not find any examples which demonstrate signing-in part. Any help please? 回答1: This was asked way back, just replying here if that could help someone who comes here searching - good example of express-jwt can be found at https://hptechblogs.com/using-json-web-token-for-authentication/ and I have also tried somewhat similar implementation which can be found at - https://github.com/Abhay-Joshi-Git/jwt-node-react/blob/master

If you can decode JWT how are they secure?

ぐ巨炮叔叔 提交于 2019-11-26 00:23:10
问题 If I get a JWT and I can decode the payload, how is that secure? Couldn\'t I just grab the token out of the header, decode and change the user information in the payload, and send it back with the same correct encoded secret? I know they must be secure, but I just would really like to understand the technologies. What am I missing? 回答1: JWTs can be either signed, encrypted or both. If a token is signed, but not encrypted, everyone can read the contents of the token, but when you don't know