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-auth-wrapper

v0.5.0

Published

Wrapper to simplify interaction with google oauth apis

Downloads

8

Readme

google-auth-wrapper

Wrapper to simplify google authentication for server side application.

It provides the following methods:

  • authorize
  • execute

Together these will allow your application to create the required artifacts to be able to interact with the google apis.

As a pre-req you need to need to add set of credentials for your application in the Google developers console as outlined here (Step 1): [https://developers.google.com/drive/v3/web/quickstart/nodejs] (https://developers.google.com/drive/v3/web/quickstart/nodejs)

authorize

authorize handles the interaction with the google oauth infrastructure and provides a plugable inteface for providing your own interaction to ask the user to navigate to the required url and to provide the code returned.

The authorize method takes the following parameters:

  • storagePath - directory in which client secrets are located and where refresh token will be stored once authorization is complete
  • clientSecrets - the name of the file which contains the google client secrets minus the '.json' file type
  • scopes - the rights you are requesting for your application
  • authCallback - your function that will be called to ask the user to naviate to a google url, authorize your application and then provide the code from that url.

authCallback has the following signature:

function(url, provideCode)

with the following parameters:

  • the url to ask the user to navigate to
  • provideCode a function you must call passing in the code that the user gets when they authorize your application at the url provided.

Once authenticated, there will be a file with the same name as your clientSecrets file but with the '.token' file type. For example, if clientSecrets was 'foo' you should end up with:

  • foo.json
  • foo.token

It should be possible to copy these files and use them with different machines and or directories.

execute

The execute function uses the contents of the files generated by the authorize call. It has the following paramters:

  • storagePath - directory in which client secrets are located and where refresh token will be stored once authorization is complete
  • clientSecrets - the name of the file which contains the google client secrets minus the '.json' file type
  • executeAction - your function that will be called

executeAction must be a function with the following paramters:

  • oauthClient - googleAuth.OAuth2 object you can use to access the google services
  • google - instance of googleapis you can use to access the google services

Examples:

list files in your drive

authorize your application to generate token file

Although it is intended that you can use the plugable aspect of authorize to integrate the authorization step into your app (using GUI or otherwise) you can also do it through simple command line app as follows:

In this example the scopes are set so that you have full read/write to your google drive:

adjust this to request the level of access required.

For this example you will to have to have stored your credentials from google in the file 'client_secret.json' and the refresh token created by the authorize call will have been stored in 'client_secret.token'. NOTE make sure to protect these two files appropriately as they give full access to whatever access level you have requested.