How to use the passport-jwt.ExtractJwt.fromExtractors function in passport-jwt

To help you get started, we’ve selected a few passport-jwt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github penta-jelly / re-radio / server / src / radio / auth / jwt.strategy.ts View on Github external
constructor(private readonly configService: ConfigService, private readonly authService: AuthService) {
    super({
      // Only take the JWT token from either "authorization" or "Authorization" headers
      jwtFromRequest: ExtractJwt.fromExtractors([
        ExtractJwt.fromHeader('authorization'),
        ExtractJwt.fromHeader('Authorization'),
      ]),
      secretOrKey: configService.get(EnvVariables.JWT_SECRET),
    });
  }
github iqbaldjulfri / lb4-jwt-role-based-auth-sample / src / auth.ts View on Github external
value(): ValueOrPromise {
    if (!this.metadata) return;

    const {strategy} = this.metadata;
    if (strategy === JWT_STRATEGY_NAME) {
      const jwtStrategy = new JwtStrategy(
        {
          secretOrKey: JWT_SECRET,
          jwtFromRequest: ExtractJwt.fromExtractors([
            ExtractJwt.fromAuthHeaderAsBearerToken(),
            ExtractJwt.fromUrlQueryParameter('access_token'),
          ]),
        },
        (payload, done) => this.verifyToken(payload, done),
      );

      // we will use Loopback's  StrategyAdapter so we can leverage passport's strategy
      // and also we don't have to implement a new strategy adapter.
      return new StrategyAdapter(jwtStrategy, JWT_STRATEGY_NAME);
    }
  }
github mylisabox / lisa-box / config / passport.js View on Github external
},
    //Enable JWT strategy
    jwt: {
      strategy: JwtStrategy,
      tokenOptions: {
        expiresInSeconds: EXPIRES_IN_SECONDS,
        secret: SECRET,
        algorithm: ALGORITHM,
        issuer: ISSUER,
        audience: AUDIENCE
      },
      options: {
        secretOrKey: SECRET,
        issuer: ISSUER,
        audience: AUDIENCE,
        jwtFromRequest: ExtractJwt.fromExtractors([ExtractJwt.fromAuthHeader(), ExtractJwt.fromUrlQueryParameter('token')]) //Authorization: JWT JSON_WEB_TOKEN_STRING
      }
    }, /*
     //Enable twitter strategy
     twitter: {
      name: 'Twitter',
      protocol: 'oauth',
      strategy: require('passport-twitter').Strategy,
      options: {
        consumerKey: 'your-consumer-key',
        consumerSecret: 'your-consumer-secret'
      }
     }
    /*,

     //Enable facebook strategy
     facebook: {
github staylor / graphql-wordpress / packages / draft / src / server / authenticate.js View on Github external
export default function addPassport(app, db) {
  const { TOKEN_KEY, TOKEN_SECRET } = process.env;

  passport.use(
    new Strategy(
      {
        jwtFromRequest: ExtractJwt.fromExtractors([
          req => {
            let token = null;
            if (req && req.cookies) {
              token = req.cookies[TOKEN_KEY];
            }
            return token;
          },
        ]),
        secretOrKey: TOKEN_SECRET,
      },
      (jwtPayload, done) => {
        if (!jwtPayload.userId) {
          done(new Error('No userId in JWT'), false);
        } else {
          done(null, jwtPayload);
        }
github wix / quix / quix-frontend / service / src / modules / auth / jwt-strategy.ts View on Github external
constructor(
    private readonly authService: AuthService,
    configService: ConfigService,
  ) {
    super({
      jwtFromRequest: ExtractJwt.fromExtractors([
        req => req.cookies[configService.getEnvSettings().AuthCookieName],
      ]),
      secretOrKey: configService.getEnvSettings().AuthEncKey,
    });
  }
github strues / boldr / packages / boldr-api / src / services / authentication / providers / jwt.js View on Github external
import passport from 'passport';
import config from '../../../../config/api';

const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;


const jwtOptions = {
  secretOrKey: config.token.secret,
  jwtFromRequest: ExtractJwt.fromExtractors([
    ExtractJwt.fromUrlQueryParameter('access_token'),
    ExtractJwt.fromBodyField('access_token'),
    ExtractJwt.fromAuthHeaderWithScheme('Bearer'),
  ]),
};

export default function configureJwt(User) {
  passport.use(new JwtStrategy(jwtOptions, async (payload, done) => {
    const NOW = new Date().getTime();
    if (payload.exp < NOW) {
      return done(null, false);
    }
    const user = await User.query().findById(payload.sub).first();
    if (!user) {
      return done(null, false, { message: 'This email is not registered.' });
    } else {
github LeadcoinNetwork / Web-App-Project / backend / rest / passport / passport-strategies.ts View on Github external
done()
      } else {
        done(null, user)
      }
    },
  )

  const extactFromCookie = request => {
    let token = null
    if (request && request.cookies) token = request.cookies["token"]
    return token
  }

  const jwtStrategy = new JWTStrategy(
    {
      jwtFromRequest: ExtractJwt.fromExtractors([extactFromCookie]),
      secretOrKey: config.auth.jwt.secret,
    },
    async (jwt, done) => {
      var user = await appLogic.models.users.tryGetUserById(jwt.id)
      if (user instanceof NotFound) {
        let err = new Error("Unauthorized")
        //@ts-ignore
        err.status = 401
        done(err)
      } else {
        done(null, user)
      }
    },
  )

  const linkedInStrategy = new LinkedInStrategy(
github LeadcoinNetwork / Web-App-Project / backend / rest / passport / passport-strategies.ts View on Github external
export function getStrategies({ appLogic }: { appLogic: AppLogic }) {
  var config = appLogic.config

  const extactFromCookie = request => {
    let token = null
    if (request && request.cookies) token = request.cookies["token"]
    return token
  }

  const jwtStrategy = new JWTStrategy(
    {
      jwtFromRequest: ExtractJwt.fromExtractors([extactFromCookie]),
      secretOrKey: config.auth.jwt.secret,
    },
    async (jwt, done) => {
      var user = await appLogic.models.users.tryGetById(jwt.id)
      if (user instanceof NotFound) {
        LogModelActions("jwt", "login failure", "unauthorized")
        let err = new Error("Unauthorized")
        //@ts-ignore
        err.status = 401
        done(err)
      } else {
        LogModelActions("jwt", "login success", user.id)
        done(null, user)
      }
    },
  )
github BigDataBoutique / ElastiQuill / backend / src / routes / auth / jwt.js View on Github external
export default function(passport) {
  passport.use(
    new JwtStrategy(
      {
        jwtFromRequest: ExtractJwt.fromExtractors([
          ExtractJwt.fromUrlQueryParameter("state"),
          ExtractJwt.fromAuthHeaderAsBearerToken(),
        ]),
        secretOrKey: jwtSecret,
      },
      (jwtPayload, done) => done(null, jwtPayload.user)
    )
  );
}