0.1.0 • Published 6 years ago

passport-slack-token v0.1.0

Weekly downloads
1
License
-
Repository
github
Last release
6 years ago

Passport-Slack-Token

Passport strategy for authenticating with Slack access tokens using the OAuth 2.0 API.

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

Installation

npm install passport-slack-token

Usage

Configure Strategy

The Slack authentication strategy authenticates users using a Slack account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a app ID and app secret.

var SlackTokenStrategy = require('passport-slack-token').Strategy;

passport.use(new SlackTokenStrategy({
    clientID: SLACK_CLIENT_ID,
    clientSecret: SLACK_CLIENT_SECRET
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ slackId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate('slack-token') to authenticate requests.

router.get('/auth/slack/token', passport.authenticate('slack-token'),
  function(req, res) {
    res.send(req.user);
  });

GET request need to have access_token and optionally the refresh_token in either the query string or set as a header. If a POST is being preformed they can also be included in the body of the request.

Credits

License

MIT License

Copyright (c) 2017 Nazar Mozol