This package was designed to simplify server-to-server tasks automation and avoid headaches when dealing with OAuth, since it is the unique method to perform most of the user-related write operations via Google APIs, such as creating a post in Blogspot or uploading a video to YouTube
It provides reliable programmatic interface which abstracts you about performing any kind of manual steps related to the authentication, authorization and handshake process to obtain a valid OAuth2 token, which is usually done manually from the user in the web browser. It support multiple associated Google accounts as well, selecting the desired one
For nightware-agnostic interface and command-line solution, see google-oauth2-token.
npm install nightmare-google-oauth2 --save
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 >
Then you must add the following URI as allowed redirects (without final slash):
Then you should see something like this:
var Nightmare =var NightmareOAuth2 =
- email - Google Account user email. Example:
- password - Google Account user password. Be aware with this. Use a temporal environment variable to store it
- clientId - Google API Client ID. You can obtain it from the Google API Console
- clientSecret - Google API Client Secret ID. You can obtain it from the Google API Console
- scope - Scope permissions URLs separated by spaces. Read more here
- useAccount - In case of multiple associated Google accounts, define the email of the desired account to use
- verificationEmail - In case that Google asks for the verification email. Not too common anyway.
.getToken(params, callback [, onChange ])
object with valid OAuth2 tokens ready to be used to call Google APIs endpoints
access_token: 'H3l5321N123sdI4HLY/RF39FjrCRF39FjrCRF39FjrCRF39FjrC_RF39FjrCRF39FjrC'token_type: 'Bearer'refresh_token: '1/smWJksmWJksmWJksmWJksmWJk_smWJksmWJksmWJksmWJksmWJk'expiry_date: 1425333671141
var params =email: 'email@example.com'password: 'sup3r_p@s$w0rd'clientId: 'blablabla' // Google API Client IDclientSecret: 'private' // Google API Client Secretscope: ''
string with the OAuth2 exchange code to be used during the OAuth2 handshake to obtain a valid token.
This process is implicitly made when calling
var params =email: 'firstname.lastname@example.org'password: 'sup3r_p@s$w0rd'clientId: 'blablabla' // Google API Client IDscope: ''
MIT © Tomas Aparicio