node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


Google Authentication From Command Line

When build command line tools, it's not very convinient for user to copy link and go to browser, then paste the authroization code to the terminal. This authentication process is not user freindly for command line tools.

This module will try to open browser and let user make decision whether grant the authorization or not, and the authorization code will be returned back to your program.

It based on project google-api-nodejs-client


see test/test.js in repository.

    gauth({ // scopes 
        access_type: 'offline', // will return a refresh token 
        scope: ''
    }, {
        // the client key you applied in 
        // the redirect url should be localhost, and your should provide a port, if not default use 80 
        client_id: "<the client id>",
        client_secret: "<client secret>",
        port: 8080,
        timeout: 5000, // in seconds 
    }, function(err, authClient, tokens) {
        if (err) return done(err);
        console.log(tokens); // tokens with access_code and refresh_code 
      userId: "me"
    }).withAuthClient(authClient) // authClient now can be used 
      .execute(function(err, profile) {
      console.log(profile, err);


(The MIT License)

Copyright (c) 2014, Villa.Gao <>;
All rights reserved.