auth.js
function(cb) {
        var at = this.brain.get(this.TOKEN_KEY),
            rt = this.brain.get(this.REFRESH_KEY);

        if (at == null || rt == null) {

            cb({
                err: null,
                msg: 'Error: No tokens found. Please authorize this app and store a refresh token'
            });
            return;
        }

        var expirTime = this.brain.get(this.EXPIRY_KEY),
            curTime = (new Date()) / 1;

        var self = this;
        if (expirTime < curTime) {
            this.oauthClient.refreshAccessToken(function(err, token) {
                if (err != null) {
                    cb({
                        err: err,
                        msg: 'Google Authentication Error: error refreshing token'
                    }, null);
                    return;
                }

                self.storeToken(token);
                cb(null, {
                    resp: token,
                    msg: 'Token refreshed'
                });
            });
        } else {
            cb(null);
        }
    }
function(cb) {
        var at = this.brain.get(this.TOKEN_KEY),
            rt = this.brain.get(this.REFRESH_KEY);

        if (at == null || rt == null) {

            cb({
                err: null,
                msg: 'Error: No tokens found. Please authorize this app and store a refresh token'
            });
            return;
        }

        var expirTime = this.brain.get(this.EXPIRY_KEY),
            curTime = (new Date()) / 1;

        var self = this;
        if (expirTime < curTime) {
            this.oauthClient.refreshAccessToken(function(err, token) {
                if (err != null) {
                    cb({
                        err: err,
                        msg: 'Google Authentication Error: error refreshing token'
                    }, null);
                    return;
                }

                self.storeToken(token);
                cb(null, {
                    resp: token,
                    msg: 'Token refreshed'
                });
            });
        } else {
            cb(null);
        }
    }
function ( cb ) { var at = this . brain . get ( this . TOKEN_KEY ) , rt = this . brain . get ( this . REFRESH_KEY ) ; if ( at == null || rt == null ) { cb ( { err : null , msg : 'Error: No tokens found. Please authorize this app and store a refresh token' } ) ; return ; } var expirTime = this . brain . get ( this . EXPIRY_KEY ) , curTime = ( new Date ( ) ) / 1 ; var self = this ; if ( expirTime < curTime ) { this . oauthClient . refreshAccessToken ( function ( err , token ) { if ( err != null ) { cb ( { err : err , msg : 'Google Authentication Error: error refreshing token' } , null ) ; return ; } self . storeToken ( token ) ; cb ( null , { resp : token , msg : 'Token refreshed' } ) ; } ) ; } else { cb ( null ) ; } }
Checks the current expire time and determines if the token is valid.
Refreshes the token if it is not valid.

@param  cb  the callback function (err, resp), use this to make api calls
Checks the current expire time and determines if the token is valid . Refreshes the token if it is not valid .