Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function setup (server) {
// TODO: Serialize user data in the database?
passport.serializeUser((user, done) => {
done(null, user._id)
})
passport.deserializeUser((id, done) => {
User.findById(id)
.then((user) => done(null, user))
.catch((error) => done(error))
})
passport.use(github.strategy)
server.use(passport.initialize())
server.use(passport.session())
log.debug('Passport setup complete')
}
// Append ledger account
const user = await dbUser.appendLedgerAccount(ledgerUser)
user.password = self.generateGithubPassword(profile.id)
return done(null, user)
})
)
}
passport.serializeUser((user, done) => {
return done(null, user)
})
passport.deserializeUser((userObj, done) => {
User.findOne({where: {username: userObj.username}})
.then(async function (dbUser) {
if (!dbUser) {
return done(new UnauthorizedError('Unknown or invalid account / password'))
}
let user = User.fromDataPersistent(dbUser)
user = await user.appendLedgerAccount()
user.password = userObj.password
done(null, user)
})
.catch(done)
})
}
// @flow
import passport from 'koa-passport';
import { Strategy } from 'passport-local';
import User from './models/User';
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
User.findOne({ id }).then(user => done(null, user || null), done);
});
passport.use(
'local',
new Strategy(
{
usernameField: 'email',
passwordField: 'password',
session: false,
},
async (email, password, done) => {
try {
const user = await User.findOne({ email });
if (!user) {
import jwt from 'jsonwebtoken';
import User from '../models/User';
import { auth as config } from './config';
// Strategies
import jwtStrategy from './strategies/jwt';
import emailStrategy from './strategies/email';
passport.use('jwt', jwtStrategy);
passport.use('email', emailStrategy);
passport.serializeUser((user, done) => {
done(null, user._id);
});
passport.deserializeUser((id, done) => {
(async () => {
try {
const user = await User.findById(id);
done(null, user);
} catch (error) {
done(error);
}
})();
});
export default function auth() {
return compose([
passport.initialize(),
]);
}
if (user) {
throw new EmailExistError();
}
const hash = yield hashAsync(password, 10);
const [id] = yield db('users').insert({ email, hash }, 'id');
done(null, { id });
} catch (err) {
done(err);
}
})));
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(wrap(function *(id, done) {
try {
const [user] = yield db('users').select('id').where({ id }).limit(1);
if (!user) {
throw new Error('user does not exist');
}
done(null, user);
} catch (err) {
done(err);
}
}));
export const authInit = passport.initialize();
export const authSession = passport.session();
export const authenticateRequest = passport.authenticate('local');
export const authenticateSignupRequest = passport.authenticate('local-signup');
import passport from 'koa-passport';
import {wrap} from 'co';
import db from '../../../shared-backend/db';
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(wrap(function *(id, done) {
try {
const [user] = yield db('users').select('id').where({id}).limit(1);
if (!user) {
done(null, false);
} else {
done(null, user);
}
} catch (err) {
done(err);
}
}));
const authInit = passport.initialize();
const authSession = passport.session();
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
import passport from 'koa-passport';
import PassportSlack from 'passport-slack';
import config from './config';
import db from './db';
import { save, getById, updateAccessToken } from './repositories/user';
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
getById(id)
.then(user => done(null, user))
.catch(done);
});
const handleUser = (accessToken, refreshToken, profile, done) => {
profile.accessToken = accessToken;
profile.refreshToken = refreshToken;
return getById(profile.id)
.then(user => {
if (!user) {
const user = {
id: profile.id,
teamId: profile._json.team_id,
profile: profile._json,
accessToken: profile.accessToken,
import { User } from 'models/users'
import { Strategy as LocalStrategy } from 'passport-local'
import FacebookTokenStrategy from 'passport-facebook-token'
import passport from 'koa-passport'
import config from './index'
passport.serializeUser((user, done) => {
done(null, user.id)
})
passport.deserializeUser(async (id, done) => {
try {
const user = await User.where({ id }).fetch()
done(null, user)
} catch (err) {
done(err)
}
})
passport.use('local', new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
}, async (email, password, done) => {
try {
const user = await User.where({ email }).fetch()
if (!user) {
initStrategies() {
if (this.strategies.length > 0) {
this.parent.parent.logger.info(
"[VelopServer][Passport] Initialize " +
this.strategies.length +
" passport strategies"
);
this.parent.app.use(passport.initialize());
this.parent.app.use(passport.session());
passport.serializeUser((user, done) => done(null, user));
passport.deserializeUser((user, done) => done(null, user));
this.strategies.map(strategy => passport.use(strategy));
}
}
import passport from 'koa-passport';
import compose from 'koa-compose';
import importDir from 'import-dir';
import User from '../models/user';
import { prefix } from '../api/config';
import * as provider from './provider';
const strategies = importDir('./strategies');
Object.keys(strategies).forEach(name => {
passport.use(name, strategies[name]);
});
passport.serializeUser((user, done) => done(null, user._id));
passport.deserializeUser((id, done) => {
(async () => {
try {
const user = await User.findById(id);
done(null, user);
} catch (error) {
done(error);
}
})();
});
export default function auth() {
return compose([
passport.initialize(),
passport.session(),
]);
}