| @@ 259-287 (lines=29) @@ | ||
| 256 | function checkToken(req, res, next) { |
|
| 257 | var token = req.headers['x-access-token']; |
|
| 258 | ||
| 259 | if (token) { |
|
| 260 | jwt.verify(token, jwtSecret, function(err, decoded) { |
|
| 261 | if (err) { |
|
| 262 | return res.status(500).json({ |
|
| 263 | errors: { |
|
| 264 | status: 500, |
|
| 265 | source: req.path, |
|
| 266 | title: "Failed authentication", |
|
| 267 | detail: err.message |
|
| 268 | } |
|
| 269 | }); |
|
| 270 | } |
|
| 271 | ||
| 272 | req.user = {}; |
|
| 273 | req.user.api_key = decoded.api_key; |
|
| 274 | req.user.email = decoded.email; |
|
| 275 | ||
| 276 | next(); |
|
| 277 | }); |
|
| 278 | } else { |
|
| 279 | return res.status(401).json({ |
|
| 280 | errors: { |
|
| 281 | status: 401, |
|
| 282 | source: req.path, |
|
| 283 | title: "No token", |
|
| 284 | detail: "No token provided in request headers" |
|
| 285 | } |
|
| 286 | }); |
|
| 287 | } |
|
| 288 | } |
|
| 289 | ||
| 290 | return { |
|
| @@ 298-328 (lines=31) @@ | ||
| 295 | checkToken: function(req, res, next) { |
|
| 296 | var token = req.headers['x-access-token']; |
|
| 297 | ||
| 298 | if (token) { |
|
| 299 | jwt.verify(token, jwtSecret, function(err, decoded) { |
|
| 300 | if (err) { |
|
| 301 | return res.status(500).json({ |
|
| 302 | errors: { |
|
| 303 | status: 500, |
|
| 304 | source: req.path, |
|
| 305 | title: "Failed authentication", |
|
| 306 | detail: err.message |
|
| 307 | } |
|
| 308 | }); |
|
| 309 | } |
|
| 310 | ||
| 311 | req.user = {}; |
|
| 312 | req.user.api_key = decoded.api_key; |
|
| 313 | req.user.email = decoded.email; |
|
| 314 | ||
| 315 | next(); |
|
| 316 | ||
| 317 | return undefined; |
|
| 318 | }); |
|
| 319 | } else { |
|
| 320 | return res.status(401).json({ |
|
| 321 | errors: { |
|
| 322 | status: 401, |
|
| 323 | source: req.path, |
|
| 324 | title: "No token", |
|
| 325 | detail: "No token provided in request headers" |
|
| 326 | } |
|
| 327 | }); |
|
| 328 | } |
|
| 329 | } |
|
| 330 | }; |
|
| 331 | ||