Git Product home page Git Product logo

botauth's Introduction

BotAuth Build Status

botauth is still pre-release and under active development. Please evaluate and provide feedback.

botauth is authentication middleware for bots built using the botframework and nodejs. botauth is leverages passportjs authentication strategies to help bot developers connect to 3rd party oauth providers. You can use botauth to connect your bot's users to their Facebook, Dropbox, or any other API protected by OAuth 2.0.

Setup

botauth is available as an npm package

npm install --save botauth

Getting Started

Create a BotAuthenticator object to configure authentication for your bot.

const botauth = require("botauth");
const DropboxOAuth2Strategy = require("passport-dropbox-oauth2").Strategy;

...

 // Initialize with the strategies we want to use
var auth = new botauth.BotAuthenticator(server, bot, {
	secret : "something secret",
	baseUrl : "https://" + WEBSITE_HOSTNAME }
);

// Configure the Dropbox authentication provider using the passport-dropbox strategy
auth.provider("dropbox",
	function(options) {
		return new DropboxOAuth2Strategy(
			{
    				clientID : DROPBOX_APP_ID,
    				clientSecret : DROPBOX_APP_SECRET,
					callbackURL : options.callbackURL
			},
			function(accessToken, refreshToken, profile, done) {
				profile.accessToken = accessToken;
				profile.refreshToken = refreshToken;
				done(null, profile);
			}
		);
	}
);

Authenticated Dialog

Use the authenticate method to make sure that the user has authenticated with a OAuth provider before continuing the dialog waterfall steps. botauth puts the user profile from the passport strategy in session.userData.botauth. authenticate returns an array of dialog steps which can be combined with your own dialog steps. Anything after authenticate will only be reached if the user successfully authenticates.

bot.dialog('/dropbox', [].concat(
	auth.authenticate("dropbox"), //use authenticate as a waterfall step
	function(session, results) {
		// this waterfall step will only be reached if authentication succeeded

		var user = auth.profile(session, "dropbox");
		session.endDialog("Welcome " + user.displayName);
	}
));

Examples

More sample code is available here.

About this project

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

botauth's People

Contributors

mattdot avatar gastonlp avatar tayzlor avatar richdizz avatar bnookala avatar navzam avatar ritazh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.