npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xoauth2

v1.2.0

Published

XOAuth2 token generation for accessing GMail SMTP and IMAP

Downloads

51,542

Readme

xoauth2

XOAuth2 token generation with node.js

Installation

npm install xoauth2

Usage

xoauth2 generates XOAUTH2 login tokens from provided Client and User credentials.

Use xoauth2.createXOAuth2Generator(options) to initialize Token Generator

Possible options values:

  • user (Required) User e-mail address
  • accessUrl (Optional) Endpoint for token generation (defaults to https://accounts.google.com/o/oauth2/token)
  • clientId (Required) Client ID value
  • clientSecret (Required) Client secret value
  • refreshToken (Required) Refresh token for an user
  • accessToken (Optional) initial access token. If not set, a new one will be generated
  • timeout (Optional) TTL in seconds
  • customHeaders (Optional) custom headers to send during token generation request yahoo requires Authorization: Basic Base64(clientId:clientSecret)
  • customParams (Optional) custom payload to send on getToken request yahoo requires redirect_uri to be specified

See https://developers.google.com/identity/protocols/OAuth2WebServer#offline for generating the required credentials

For Google service account the option values are:

  • service (Required) Service account email.
  • user (Required) User e-mail address
  • scope (Required) OAuth2 scope.
  • privateKey (Required) Private key issued for the service account in PEM format, as a string.
  • serviceRequestTimeout (Optional) Expiration value to use in the token request in seconds. Maximum is 3600.
  • accessUrl (Optional) Endpoint for token generation (defaults to https://accounts.google.com/o/oauth2/token)
  • accessToken (Optional) initial access token. If not set, a new one will be generated
  • timeout (Optional) TTL in seconds
  • customHeaders (Optional) custom headers to send during token generation request
  • customParams (Optional) custom payload to send on getToken request

Methods

Request an access token

Use xoauth2obj.getToken(callback) to get an access token. If a cached token is found and it should not be expired yet, the cached value will be used.

Request for generating a new access token

Use xoauth2obj.generateToken(callback) to get an access token. Cache will not be used and a new token is generated.

Update access token values

Use xoauth2obj.updateToken(accessToken, timeout) to set the new value for the xoauth2 access token. This function emits 'token'

Events

If a new token value has been set, 'token' event is emitted.

xoauth2obj.on("token", function(token){
    console.log("User: ", token.user); // e-mail address
    console.log("New access token: ", token.accessToken);
    console.log("New access token timeout: ", token.timeout); // TTL in seconds
});

Example

var xoauth2 = require("xoauth2"),
    xoauth2gen;

xoauth2gen = xoauth2.createXOAuth2Generator({
    user: "[email protected]",
    clientId: "{Client ID}",
    clientSecret: "{Client Secret}",
    refreshToken: "{User Refresh Token}",
    customHeaders: {
      "HeaderName": "HeaderValue"
    },
    customPayload: {
      "payloadParamName": "payloadValue"
    }
});

// ... or for a Google service account
xoauth2gen = xoauth2.createXOAuth2Generator({
    user: "[email protected]",
    service: '{Service Email Address}',
    scope: 'https://mail.google.com/',
    privateKey: '{Private Key in PEM format}'
});

// SMTP/IMAP
xoauth2gen.getToken(function(err, token){
    if(err){
        return console.log(err);
    }
    console.log("AUTH XOAUTH2 " + token);
});

// HTTP
xoauth2gen.getToken(function(err, token, accessToken){
    if(err){
        return console.log(err);
    }
    console.log("Authorization: Bearer " + accessToken);
});

License

MIT