How to use the passport.Passport function in passport

To help you get started, we’ve selected a few passport 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 lskjs / lskjs / packages / auth / src / server.js View on Github external
this.config = {};
      }

      if (this.config.telegram) {
        this.tbot = require('./tbot').default(ctx, this);
      }
      if (!this.config.socials) this.config.socials = {};
      this.models = this.getModels();
      // ctx.models.User = this.models.User;

      this.controller = this.getController();
      this.Strategy = require('./server/Strategy').default(ctx, this);
      this.strategyProviders = this.getStrategies();
      this.strategies = {};

      this.passportService = new Passport();
      const providers = get(this, 'config.providers', {});
      // console.log({ providers });

      forEach(providers, (config) => {
        const { provider, type, ...strategyConfig } = config;
        // console.log({ provider, type });

        const StrategyProvider = this.strategyProviders[type];
        if (!StrategyProvider) return;
        const strategy = new StrategyProvider({
          provider,
          type,
          config: strategyConfig,
        });
        // console.log({strategy});
        if (!strategy) return;
github lskjs / lskjs / packages / lsk-modules / packages / auth / src / server.js View on Github external
this.config = get(ctx, 'config.auth', {});

      if (this.config.telegram) {
        this.tbot = require('./tbot').default(ctx, this);
      }
      if (!this.config.socials) this.config.socials = {};
      this.initOnlineService();
      this.models = this.getModels();
      // ctx.models.User = this.models.User;

      this.controller = this.getController();
      this.Strategy = require('./server/Strategy').default(ctx, this);
      this.strategyProviders = this.getStrategies();
      this.strategies = {};

      this.passportService = new Passport();
      const providers = get(this, 'config.providers', {});
      // console.log({ providers });

      forEach(providers, (config) => {
        const { provider, type, ...strategyConfig } = config;
        // console.log({ provider, type });

        const StrategyProvider = this.strategyProviders[type];
        if (!StrategyProvider) return;
        const strategy = new StrategyProvider({
          provider,
          type,
          config: strategyConfig,
        });
        // console.log({strategy});
        if (!strategy) return;
github wisnuc / appifi / src / middleware / Auth.js View on Github external
return Array.isArray(value) ? value : []
      }
    })

    // this.users = users
    this.secret = secret

    let jwtOpts = {
      secretOrKey: this.secret,
      jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('jwt')
    }

    // this is not officially documented
    // see https://github.com/jaredhanson/passport/issues/27
    this.pp = new passport.Passport()
    this.pp.use(new BasicStrategy(this.handleBasicAuth.bind(this)))
    this.pp.use(new JwtStrategy(jwtOpts, this.handleJwtAuth.bind(this)))
    this.middleware = this.pp.initialize()
  }
github apostrophecms / apostrophe / lib / modules / apostrophe-login / index.js View on Github external
construct: function(self, options) {

    self.passport = new Passport();

    // Set the `serializeUser` method of `passport` to serialize the
    // user by storing their user ID in the session.

    self.enableSerializeUsers = function() {
      self.passport.serializeUser(function(user, done) {
        done(null, user._id);
      });
    };

    self.randomKey = function(len) {
      var buf = [];
      var chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
      var charlen = chars.length;

      for (var i = 0; i < len; ++i) {
github alrighty / react-universal-starter-kit / modules / server / passport / index.js View on Github external
import passport from 'passport'
import { github } from './strategies'
import { serializeUser, deserializeUser } from './encoding'

// Create new instance of Passport
const pass = new passport.Passport()

// User encoding
pass.serializeUser(serializeUser)
pass.deserializeUser(deserializeUser)

pass.use(github)

export default pass
github gitana / cloudcms-server / server / index.js View on Github external
app.use(function(req, res, next) {

                                var passport = new Passport();
                                passport._key = "passport-" + req.virtualHost;

                                req._passport = {};
                                req._passport.instance = passport;

                                if (req.session && req.session[passport._key])
                                {
                                    // load data from existing session
                                    req._passport.session = req.session[passport._key];
                                }

                                // add this in
                                req.passport = req._passport.instance;

                                // passport - serialize and deserialize
                                req.passport.serializeUser(function(user, done) {
github rkusa / koa-passport / lib / index.js View on Github external
var passport = require('passport')
var Passport = require('passport').Passport
var framework = require('./framework/koa')()

passport.framework(framework)

var KoaPassport = function () {
  Passport.call(this)
  this.framework(framework)
}
require('util').inherits(KoaPassport, Passport)

// Export default singleton.
module.exports = passport

// Expose constructor
module.exports.KoaPassport = KoaPassport
github DefinitelyTyped / DefinitelyTyped / types / passport / passport-tests.ts View on Github external
passport.authenticate('google', {
            scope:
                ['https://www.googleapis.com/auth/userinfo.profile']
        }));
    app.get('/auth/google/callback',
        passport.authenticate('google', authOption), successCallback);
}

function ensureAuthenticated(req: express.Request, res: express.Response, next: (err?: any) => void) {
    if (req.isAuthenticated()) { return next(); }
    if (req.isUnauthenticated()) {
        res.redirect('/login');
    }
}

const passportInstance = new passport.Passport();
passportInstance.use(new TestStrategy());

const authenticator = new passport.Authenticator();
authenticator.use(new TestStrategy());

declare global {
    namespace Express {
        interface User {
            username: string;
            id?: string;
        }
    }
}

app.use((req: express.Request, res: express.Response, next: (err?: any) => void) => {
    if (req.user) {
github u-wave / core / src / plugins / passport.js View on Github external
function configurePassport(uw, options) {
  const passport = new Passport();

  async function localLogin(email, password) {
    return uw.users.login({ type: 'local', email, password });
  }

  async function socialLogin(accessToken, refreshToken, profile) {
    return uw.users.login({
      type: profile.provider,
      profile,
    });
  }

  async function serializeUser(user) {
    return user.id;
  }
  async function deserializeUser(id) {
github zkiiito / SURF / code / routerAdmin.js View on Github external
var express = require('express');
var Passport = require('passport');
var passport = new Passport.Passport();
var LocalStrategy = require('passport-local').Strategy;
var app = express.Router();

var Config = require('./Config');
var UserController = require('./adminController/User');
var WaveController = require('./adminController/Wave');
var WaveInviteController = require('./adminController/WaveInvite');
var MessageController = require('./adminController/Message');

var adminDir = __dirname.replace('code', 'admin');

app.use('/css', express.static(adminDir + '/css'));
app.use('/fonts', express.static(adminDir + '/fonts'));
app.use('/js', express.static(adminDir + '/js'));

app.use(function (req, res, next) {