Passport strategy for authenticating with Threads using the OAuth 2.0 API.
This module lets you authenticate using Threads in your Node.js applications. By plugging into Passport, Threads authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
This is a module for node.js and is installed via npm:
npm install passport-threads --save
The Threads authentication strategy authenticates users using a Threads 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 client ID, client secret, scope, and callback URL.
passport.use(new ThreadsStrategy({
clientID: THREADS_CLIENT_ID,
clientSecret: THREADS_CLIENT_SECRET,
scope: ['user.info.basic'],
callbackURL: "https://localhost:3000/auth/threads/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({ threadsId: profile.id }, function (err, user) {
return done(err, user);
});
}
));
Threads only allows https callback urls. This blog article explains the quickest way to enable https for your Express server.
Use passport.authenticate()
, specifying the 'threads'
strategy, to authenticate requests.
For example, as route middleware in an Express application:
app.get('/auth/threads',
passport.authenticate('threads')
);
app.get('/auth/threads/callback',
passport.authenticate('threads', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
}
);
By default we are using version 1.0. If other version is required it can be used like the following example.
passport.use(new ThreadsStrategy({
version: "v1.0",
clientID: THREADS_CLIENT_ID,
clientSecret: THREADS_CLIENT_SECRET,
scope: ['threads_basic'],
callbackURL: "https://localhost:3000/auth/threads/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({ threadsId: profile.id }, function (err, user) {
return done(err, user);
});
}
));
In case you never heard about the ISC license it is functionally equivalent to the MIT license.
See the LICENSE file for details.