google-oauth

0.0.2 • Public • Published

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('/');
   });
    }
});
 

Readme

Keywords

none

Package Sidebar

Install

npm i google-oauth

Weekly Downloads

4

Version

0.0.2

License

none

Last publish

Collaborators

  • wanasit