GithubHelp home page GithubHelp logo

juaneduardodelgado / passport-smartthings Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeff-blaisdell/passport-smartthings

0.0 1.0 0.0 188 KB

A Passport.js OAuth 2.0 strategy for Smartenit

License: Apache License 2.0

JavaScript 100.00%

passport-smartthings's Introduction

passport-smartthings

A Passport.js OAuth 2.0 strategy for Smart Things.

Passport strategy for authenticating with Smart Things using the OAuth 2.0 API.

This module lets you authenticate using Smart Things in your Node.js applications. By plugging into Passport, Smart Things authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-smartthings

Usage

Configure Strategy

var SmartThingsStrategy = require('passport-smartthings').Strategy

passport.use(new SmartThingsStrategy({
    clientID: SMARTTHINGS_CLIENT_ID,
    clientSecret: SMARTTHINGS_CLIENT_SECRET
}));

Authenticate Requests

Use passport.authenticate(), specifying the 'smartthings' strategy, to authenticate requests.

Note Smart Things requires the presence of a scope permission such as "app".

For example, as route middleware in an Express application:

app.get(
    '/auth/smartthings', 
    passport.authenticate('smartthings', { scope: ['app'] })
);

app.get('/auth/smartthings/callback',
    passport.authenticate('smartthings', { scope: ['app'] }),
    function(req, res) { 
        res.redirect('/'); 
    }
);

Extended Permissions

If you need extended permissions from the user, the permissions can be requested via the scope option to passport.authenticate().

For example, this authorization requests permission to the app tied to the clientID:

app.get(
    '/auth/smartthings', 
    passport.authenticate('smartthings', { scope: ['app'] })
);

Profile

The above configuration will populate the passport profile in session with the Smart Things access token and applicable api endpoints available to the logged in user for further api requests. The endpoints are as described in Step 8 of the Web Services Smart App documentation found here SmartApp Web Services Developers Guide. For example usage checkout examples/app.js dashboard express route.

passport-smartthings's People

Contributors

jeff-blaisdell avatar

Watchers

Juan Eduardo Delgado Medina 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.