google-oauth

Simplified OAuth helper for Google API

npm install google-oauth
5 downloads in the last week
29 downloads in the last month

Google-OAuth

Simplified OAuth helper for Google APIs

Example


var OAuth = require('../GoogleOAuth');
var oauth = new OAuth.OAuth2(
  consumer_key, 
  consumer_secret, 
  'http://localhost:8082/authentication'); 

server.get('/authentication', function(req, res){

    if(!req.query.code){

      //Redirect the user to Authentication From,
      // Set authentication scope to google calendar api
      oauth.getGoogleAuthorizeTokenURL( ['https://www.googleapis.com/auth/calendar'], function(err, redirecUrl) {
          if(err) return res.send(500,err);
        return res.redirect(redirecUrl);
      });

    }else{
      //Get access_token from the code
      oauth.getGoogleAccessToken(req.query, function(err, access_token, refresh_token) {
          if(err) return res.send(500,err);

          req.session.access_token = access_token;
          req.session.refresh_token = refresh_token;
        return res.redirect('/');
      });
    }
});
npm loves you