Hubot utility functions for authenticating to google apis
Last updated 4 years ago by aaaschmitt .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hubot-google-auth 
SYNC missed versions from official npm registry.


Hubot utility functions for authenticating to google apis

Check out an example script here.


npm install --save hubot-google-auth


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


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.


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 ='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>"

    	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}"

    		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

Current Tags

  • 1.2.0                                ...           latest (4 years ago)

6 Versions

  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
Dependents (1)

Copyright 2014 - 2016 © |