node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


nodejs oauth wrapper for gmail


OAuth for Gmail

This module makes it easy to generate Oauth (v1) and Xoauth strings for use with gmail's IMAP servers.


$ npm install gmail-oauth


var client = require(__dirname + '../lib/index').createClient();

client.getRequestToken('', function (error, results) {
  if (error) 
    throw new Error(error);

  // get the user to go to the authorization URL...

  process.stdout.write('Enter verification code: ');

  process.stdin.once('data', function (text) {
    var code = text.trim();
    client.getAccessToken(results, code, function(error, results) {
      if (error)  
        throw new Error(error);
      console.log(JSON.stringify(results, null, 2));

Create a new oauth client.

options is an object which may specify:

  • consumerKey: the consumerKey value to pass to Gmail/Google
  • consumerSecret: the consumerSecret value to pass to Gmail/Google
  • callbackUrl: which callbackUrl to use for this client. Defaults to 'oob'