Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var jwt = require('express-jwt');
- var secret = require('../config').secret;
- // utility to parse token from headers.authorization
- function getTokenFromHeader(req) {
- if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Token') {
- return req.headers.authorization.split(' ')[1];
- }
- return null;
- }
- // methods for routes where auth is required and optional
- var auth = {
- // both these methods validate the token against the secret in config
- required: jwt({
- secret: secret,
- userProperty: 'payload',
- getToken: getTokenFromHeader
- }),
- optional: jwt({
- secret: secret,
- userProperty: 'payload',
- credentialsRequired: false,
- getToken: getTokenFromHeader
- })
- };
- module.exports = auth;
Advertisement
Add Comment
Please, Sign In to add comment