authentication and autherization event logging #49

Closed
hlobil opened this Issue Aug 2, 2012 · 1 comment

Projects

None yet

2 participants

@hlobil
hlobil commented Aug 2, 2012

Is there anyway to hook into passportjs to listen for authentication and autherization events?

passport.on('error', function(data){
console.log("%s", data);
});

I would like to remove logging from the following code and place it more centrally.

function facebookConnect(accessToken, refreshToken, profile, done) {

    var logEntry = {
        accessToken:accessToken,
        refreshToken:refreshToken,
        profile:profile,
        email:profile.emails
    };

    logger.debug(logEntry);

    app.Account
        .findOne({ domain:profile.domain, id:profile.id}, function (err, account) {
            if (err) {
                logger.error('facebook authz error');
                return done(err);
            }

            if (account) {
                logger.error('facebook account found');
                return done(null, account);
            } else {
                logger.log('creating new account');
                var newAccount = new app.Account();
                newAccount.domain = profile.domain;
                newAccount.id = profile.id;
                newAccount.username = profile.displayName;

                newAccount.emails = profile.emails.map(function (email) {
                    return email.value;
                });

                newAccount.token = accessToken;
                newAccount.tokenSecret = refreshToken;


                return done(null, newAccount);

            }
        });

}

Thank you,

Pavel

@jaredhanson
Owner

People tend to want different information in their logs, so rather than try to plumb things through Passport itself, it is preferred to log at the application-layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment