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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gupshup-oauth

v1.0.9

Published

This is a sample oauth implementation for the bots platform on gupshup.io devtools

Downloads

31

Readme

gupshup-oauth

This is a sample oauth implementation for the bots platform on gupshup.io dev-box ide

Installation

npm install gupshup-oauth

Usage

1. Create a config.json with following credentials

var config = {
    "oauth_creds": {
        "botname": "<gupshup_botname>",
        "apikey": "<gupshup_apikey>",
        "channels": {
            "github": {
                /* Callback url here is gupshup url for github channel. 
                ** Kindly enter your botname in <gupshup_botname. 
                ** You can also change it to your own callback url but you will have to handle auth on your server instead
                **/
                "callbackURL": "https://www.gupshup.io/developer/bot/<gupshup_botname>/gupshup-oauth/github/callback",
                "baseUrl": "https://github.com/",
                "authUrl": "login/oauth/authorize",
                "accessTokenUrl": "login/oauth/access_token",
                "clientSecret": "<client_secret_key>",
                "clientID": "<client_id>",
                "scope": "first_name,last_name,email"
            },
            "facebook": {
                /* Callback url here is gupshup url for facebook channel. 
                ** Kindly enter your botname in <gupshup_botname. 
                ** You can also change it to your own callback url but you will have to handle auth on your server instead
                **/
                "callbackURL": "https://www.gupshup.io/developer/bot/<gupshup_botname>/gupshup-oauth/facebook/callback",
                "baseUrl": "",
                "authUrl": "https://www.facebook.com/v2.8/dialog/oauth",
                "accessTokenUrl": "https://graph.facebook.com/oauth/access_token",
                "clientSecret": "<client_secret_key>",
                "clientID": "<client_id>",
                "scope": "public_profile email"
            }
        }
    }
}

If you are using gupshup callback url. Kindly make sure that the structure is as follows.

https://www.gupshup.io/developer/bot/<gupshup_botname>/gupshup-oauth/<channel_name>/callback
where channel_name is the key for the channels Object, eg.facebook,github,twitter or your own oauth.

2. Use these creds inside your index.js file (You can refer to the botIndex.js in examples for better understanding.)

//Fetch config
var authCreds = require('./config.json').oauth_creds;
//Register new oauth instance with your auth config
var gupshupAuth = require('gupshup-oauth')(authCreds);

3. You need to specify any handling that you wish to do before and after the auth is finished.

//This will be called on auth request completion,
// the oauth channel will share code to fetch auth token
authCreds.preCallback = function(context, event, channel, done) {
        //Do what you want to achieve with the code
        done(context, event, channel);
}

//This will be called after we have saved creds to roomlevel data,
// You will still have control over the code received.
authCreds.postCallback = function(context, event, channel, done) {
    //Do what you want to achieve with the code
    done(context, event, channel);
}

4. Fetch the signend_link to share it with your users. This needs to be done in the MessageHandler section

var facebook_signed_url = gupshupAuth.getSignedURL('facebook', event.contextobj.contextid);
var facebook_signed_url = gupshupAuth.getSignedURL('github', event.contextobj.contextid);

The structure is.

gupshupAuth.getSignedURL(<channel_name>, <state>);

Kindly note that state is required here and channel_name could be only from the auth creds defined in the config.json

5. The last and the most important step where you have to filter all gupshup-oauth http responses in the HttpEndpointHandler section

if (path.match(/gupshup-oauth/g)) {
    //Handling oauth specific urls
    gupshupAuth.execute(context, event);
} else {
    context.sendResponse('This is response from http \n' + JSON.stringify(event, null, '\t'));
    //Put your custom url match patterns.
}

#Congratulations!!! thats all.

You can refer to botIndex.js for a better understanding of the above mentioned steps.

Kindly share your feedback, we will be very pleased to help you.

Visit gupshup.io to create your bots and use them in your code.