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

google-oauth2-token

v0.2.0

Published

Get a fresh OAuth2 token for Google APIs in just one command. Automation rules

Downloads

13

Readme

google-oauth2-token Build Status NPM version

No headaches. Automation wins. Get a fresh OAuth2 token ready to be used for Google APIs calls in just one command

This package was designed to simplify server-to-server tasks automation and avoid headaches when dealing with OAuth, since it the unique method to perform most of the write operations via Google APIs

It provides a simple programmatic and command-line interface which abstracts you about performing any kind of manual steps related to the authorization and handshake process to obtain a valid OAuth2 token

This uses PhantomJS + Nightmare via nightmare-google-oauth2 plugin

Google API credentials setup

Be sure you have a project and a Web Application credentials with a Client ID and Client Secret from the Google API Console > API & Auth > Credentials

Then you must add the following URI as allowed redirects (without final slash):

http://localhost:8488

Then you should see something like:

Installation

npm install -g google-oauth2-token

Command-line interface

$ google-oauth2-token --help

Get Google OAuth2 token.
Usage: google-oauth2-token [options]

Options:
  --help, -h           Show help                                                
  --email, -e          Google Account user email. Available as env variable:
                       GOOGLE_EMAIL                                             
  --password, -p       Google Account user password. Available as env variable:
                       GOOGLE_PASSWORD                                          
  --client-id, -c      Google API Client ID                           [required]
  --client-secret, -x  Google API Client Secret. Available as env variable:
                       GOOGLE_CLIENTSECRET                                      
  --scope, -s          Google API permissions scope                   [required]
  --json, -j           Print tokens to stdout as JSON                           

Examples:
  google-oauth2-token -e [email protected] -p myP@ssw0rd 
  --scope https://www.googleapis.com/auth/youtube.upload
  --client-id xxxx ---client-secret xxxx

Example

$ [email protected] GOOGLE_PASSWORD=p@s$w0rd google-oauth2-token \
  --client-id xxxx \
  --secret-client xxxx \
  --scope https://www.googleapis.com/auth/youtube \
  --json

The above show print something like:

{ 
  "access_token": "H3l5321N123sdI4HLY/RF39FjrCRF39FjrCRF39FjrCRF39FjrC_RF39FjrCRF39FjrC",
  "token_type": "Bearer",
  "refresh_token": "1/smWJksmWJksmWJksmWJksmWJk_smWJksmWJksmWJksmWJksmWJk",
  "expiry_date": 1425333671141 
}

Programmatic API

var GoogleOAuth2 = require('google-oauth2-token')

var params = {
  email: '[email protected]',
  password: 'sup3r_p@s$w0rd',
  clientId: 'blablabla', // Google API Client ID
  clientSecret: 'private', // Google API Client Secret
  scope: 'https://www.googleapis.com/auth/youtube.upload'
}

GoogleOAuth2(params, function (err, tokens) {
  if (err) return console.error(err)

  console.log('OAuth2 access token:', tokens.access_token)
  console.log('OAuth2 refresh token:', tokens.refresh_token)
  console.log('OAuth2 token expiry date:', new Date(tokens.expiry_date))
})

Params

  • email required - Google Account user email. Example: [email protected]
  • password required - Google Account user password. Be aware with this. Use a temporal environment variable to store it
  • clientId required - Google API Client ID. You can obtain it from the Google API Console
  • clientSecret required - Google API Client Secret ID. You can obtain it from the Google API Console
  • scope required - Scope permissions URLs separated by spaces. Read more here

License

MIT © Tomas Aparicio