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

hubot-google-auth

v1.2.0

Published

Hubot utility functions for authenticating to google apis

Downloads

3

Readme

hubot-google-auth

Hubot utility functions for authenticating to google apis

Check out an example script here.

Install

npm install --save hubot-google-auth

Configuration

You will need to generate a client_secret.json file to authenticate via google's oauth2 protocol. Instructions for doing this can be found by following step 1 here.

Using your client_secret.json you can initialize the HubotGoogleAuth object like this:

HubotGoogleAuth = require 'hubot-google-auth'

# Note that we need acess to the robot's brain to init the auth object
# Scopes should be a text string of scope urls, each seperated by a semicolon (;)
# Service name should be the google service that is being used or that you would like to share tokens between bots for
auth = new HubotGoogoleAuth ServiceName, CLIENT_ID, CLIENT_SECRET, REDIRECT_URL, SCOPES, robot.brain

Usage

Inteneded be be used by hubot scripts to perform google auth by storing api tokens in the brain relative to a certain service name that is provided. This is useful because it allows you to require this module in several different scripts that need to use google auth and have all of these scripts use the same keys to get and set api tokens from hubots brain.

Sample script

See an extened example script here. Check out the package that it comes from here.

CLIENT_ID = process.env.HUBOT_DRIVE_CLIENT_ID
CLIENT_SECRET = process.env.HUBOT_DRIVE_CLIENT_SECRET
REDIRECT_URL = process.env.HUBOT_DRIVE_REDIRECT_URL
SCOPES = 'https://www.googleapis.com/auth/drive'

HubotGoogleAuth = require 'hubot-google-auth'

module.exports = (robot) ->
	
	# We need to initialize the auth client here because it is initialzed with the brain
    auth = new HubotGoogleAuth "GoogleDrive", CLIENT_ID, CLIENT_SECRET, REDIRECT_URL, SCOPES, robot.brain

    # Tokens may be null initially
    tokens = auth.getTokens()

    # Google apis are exposed via the google object
    # See the googleapis npm package for how to use these apis
    drive = auth.google.drive('v2')

    robot.respond /show tokens/i, (msg)->

    	if !tokens.token
    		msg.send "No tokens found"
    		msg.send "Please copy the code at this url #{auth.generateAuthUrl()}"
    		msg.send "Then use the command @hubot set code <code>"
    		return

    	msg.send auth.getTokens()

    robot.respond /set code (.+)/i, (msg)->
    	code = msg.match[1]

    	# Gets new token and refresh token and stores into brain
    	auth.setCode code, (err, resp)->
    		if err
    			msg.send "Could not obtain tokens with code: #{code}"
    			return

    		msg.send "Code successfully set. Tokens now stored in brain for service: #{auth.serviceName}"

    robot.respond /drive request/i, (msg)->
		drive.files.get {fileId: 'some_id'}, (err, resp)->
			if err
				return msg.send "ERROR: could not get file: #{err}"

			msg.send resp.title