user6468132
user6468132

Reputation: 403

Cannot use aouth in Slack

I try to use Oauth 2.0 in Slack.

What I have done so far is; I created a application from here; https://api.slack.com/apps I get the client id and client secret from app credentials.

And then, I install passport-slack as npm install passport-slack

As https://github.com/mjpearson/passport-slack suggests I added the following code with mu client id and client secret.

passport.use(new SlackStrategy({
    clientID: CLIENT_ID,
    clientSecret: CLIENT_SECRET
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ SlackId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

But it throws an error as;

[ReferenceError: SlackStrategy is not defined]

I required passport-slack as;

var passport = require("passport-slack");

Why I cannot find the user? And it gives me an error?

Upvotes: 0

Views: 298

Answers (1)

sn0wFox
sn0wFox

Reputation: 46

First thing:

var passport = require("passport-slack");

You should import passport like this:

var passport = require("passport");

Passport is an authentification middleware, which use 'strategies'. Passport-slack is one of these strategies. Here, you just want the middleware.

Second thing:

[ReferenceError: SlackStrategy is not defined]

You need to import the SlackStrategy like this :

var SlackStrategy = require("passport-slack").Strategy;

This time, you want a strategy, so that's the way we import it.

Last thing:

Why I cannot find the user? And it gives me an error?

I'm not really sure about what you mean here, but i guess you get an error telling you 'User is undefined' or something like that. To learn more about this User.findOne() function, you can take a look at this topic.

Upvotes: 2

Related Questions