express-jwt

Pass JWT in Header

[亡魂溺海] 提交于 2019-12-06 09:19:06
问题 I am learning JWT with NodeJs. I am stuck at passing the JWT in header actually i do not know how to do this. index.js file var express = require('express'), app = express(), routes = require('./routes'), bodyParser = require('body-parser'), path = require('path'), ejs = require('ejs'), jwt = require('jsonwebtoken'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.post('/home',routes

Using Passport for Authentication of API Endpoints

时光毁灭记忆、已成空白 提交于 2019-12-05 03:17:47
问题 Following a couple tutorials on adding authentication using jsonwebtoken, passport, and passport-local I've become stuck on integrating it into my project. I want it so that any requests to any of the API endpoints require authentication, and also any requests to the front end which touch the API require authentication. What is happening now is I can get a user to log in and register but once they are logged in they are still unable to visit a page which is requiring authentication. The user

How is angular-jwt decoding my JWT without a secret?

馋奶兔 提交于 2019-12-05 02:50:55
The Auth0 team created something called "angular-jwt" which has a jwtHelper class. This thing successfully decodes a local JWT without the secret I used on the server. How did this happen? If they are not secure, then what is the point of using a secret to sign/encrypt them? Function on the server that encrypts the token (using "jsonwebtoken"): function createToken (user) { return jwt.sign(_.omit(user, 'password'), config.secret, { expiresInMinutes: 60*5 }); } Code from the client: angular .module('sample.home', [ 'ui.router', 'angular-storage', 'angular-jwt' ]) .config(function (

Pass JWT in Header

回眸只為那壹抹淺笑 提交于 2019-12-04 17:37:07
I am learning JWT with NodeJs. I am stuck at passing the JWT in header actually i do not know how to do this. index.js file var express = require('express'), app = express(), routes = require('./routes'), bodyParser = require('body-parser'), path = require('path'), ejs = require('ejs'), jwt = require('jsonwebtoken'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.post('/home',routes.loginUser); app.get('/', function(req, res) { res.render('index'); }); app.get('/home',function(req, res)

SailsJS - using sails.io.js with JWT

99封情书 提交于 2019-12-04 11:27:13
问题 I have implemented an AngularJS app, communicating with Sails backend through websockets, using sails.io.js. Since the backend is basically a pure API and will be connected to from other apps as well, I'm trying to disable sessions completely and use JWT. I have set up express-jwt and can use regular HTTP requests quite nicely, but when I send a request through sails.io.js, nothing happens at all - websocket request keeps pending on the client, and there's nothing happening on the server

Handling parameterised routes in express-jwt using unless

 ̄綄美尐妖づ 提交于 2019-12-04 03:24:47
Given the following route: router.get('/api/members/confirm/:id, function (req, res, next) how do I specify the route to be excluded? I have tried: app.use('/api', expressJwt({ secret: config.secret}).unless({path: ['/api/members/confirm']})); and app.use('/api', expressJwt({ secret: config.secret}).unless({path: ['/api/members/confirm/:id']})); but neither path in the unless array seem to work? The express-jwt module is using express-unless to give you this unless method, which doesn't accept express' :param path arguments syntax. But it does accept a regex, so you could do this: app.use('

Using Passport for Authentication of API Endpoints

筅森魡賤 提交于 2019-12-03 17:36:29
Following a couple tutorials on adding authentication using jsonwebtoken, passport, and passport-local I've become stuck on integrating it into my project . I want it so that any requests to any of the API endpoints require authentication, and also any requests to the front end which touch the API require authentication. What is happening now is I can get a user to log in and register but once they are logged in they are still unable to visit a page which is requiring authentication. The user gets a 401 error. It's like the token isn't being passed correctly in the request. I tried adding an

Super test, test secure REST API

筅森魡賤 提交于 2019-12-03 09:45:37
问题 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

SailsJS - using sails.io.js with JWT

十年热恋 提交于 2019-12-03 07:16:27
I have implemented an AngularJS app, communicating with Sails backend through websockets, using sails.io.js. Since the backend is basically a pure API and will be connected to from other apps as well, I'm trying to disable sessions completely and use JWT. I have set up express-jwt and can use regular HTTP requests quite nicely, but when I send a request through sails.io.js, nothing happens at all - websocket request keeps pending on the client, and there's nothing happening on the server (with "silly" log level). I've tried patching sails.io.js to support the query parameter , and when

How to send a token with an AJAX request from jQuery

泪湿孤枕 提交于 2019-12-03 05:38: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