passport-smartthings

0.3.7 • Public • Published

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.

Package Sidebar

Install

npm i passport-smartthings

Weekly Downloads

9

Version

0.3.7

License

Apache 2.0

Last publish

Collaborators

  • jeff-blaisdell