auth/google-oauth.js
function authCodeCallback(req, res, next) {
    var code = req.code;
    if (!code) {
        return res.status(400).send('Missing auth code');
    }

    var tokenData = {
        code: code,
        client_id: _cfg.clientId,
        client_secret: _cfg.clientSecret,
        grant_type: 'authorization_code',
        redirect_uri: _cfg.redirectURI
    };

    getToken(tokenData, function (err, authData) {

        if (err) {
            debug('Error getting new access token: %s', err);
            return res.sendStatus(401);
        } else {
            req.session.auth = authData;

            if (_cfg.profile === true) { //optional step to get profile data
                debug('Requesting profile data');
                getProfileData(authData.access_token, function(err, data) {
                    if (err) {
                        debug('Error getting profile data: %s', err.message);
                        return next(err);
                    }
                    req.session.auth.profile = data;
                    res.sendStatus(200);
                });
            } else {
                res.sendStatus(200);
            }


        }
    });
}
function authCodeCallback(req, res, next) {
    var code = req.code;
    if (!code) {
        return res.status(400).send('Missing auth code');
    }

    var tokenData = {
        code: code,
        client_id: _cfg.clientId,
        client_secret: _cfg.clientSecret,
        grant_type: 'authorization_code',
        redirect_uri: _cfg.redirectURI
    };

    getToken(tokenData, function (err, authData) {

        if (err) {
            debug('Error getting new access token: %s', err);
            return res.sendStatus(401);
        } else {
            req.session.auth = authData;

            if (_cfg.profile === true) { //optional step to get profile data
                debug('Requesting profile data');
                getProfileData(authData.access_token, function(err, data) {
                    if (err) {
                        debug('Error getting profile data: %s', err.message);
                        return next(err);
                    }
                    req.session.auth.profile = data;
                    res.sendStatus(200);
                });
            } else {
                res.sendStatus(200);
            }


        }
    });
}
function authCodeCallback ( req , res , next ) { var code = req . code ; if ( ! code ) { return res . status ( 400 ) . send ( 'Missing auth code' ) ; } var tokenData = { code : code , client_id : _cfg . clientId , client_secret : _cfg . clientSecret , grant_type : 'authorization_code' , redirect_uri : _cfg . redirectURI } ; getToken ( tokenData , function ( err , authData ) { if ( err ) { debug ( 'Error getting new access token: %s' , err ) ; return res . sendStatus ( 401 ) ; } else { req . session . auth = authData ; if ( _cfg . profile === true ) { //optional step to get profile data debug ( 'Requesting profile data' ) ; getProfileData ( authData . access_token , function ( err , data ) { if ( err ) { debug ( 'Error getting profile data: %s' , err . message ) ; return next ( err ) ; } req . session . auth . profile = data ; res . sendStatus ( 200 ) ; } ) ; } else { res . sendStatus ( 200 ) ; } } } ) ; }
This gets called when someone hits the auth code callback endpoint It expects that a valid google auth code is supplied through either the "code" query param or in the request body.  Let's setAuthCodeOnReq handle getting the auth code. If anything fails, it returns an error status, otherwise a 200
This gets called when someone hits the auth code callback endpoint It expects that a valid google auth code is supplied through either the code query param or in the request body . Let s setAuthCodeOnReq handle getting the auth code . If anything fails it returns an error status otherwise a 200