passport-annict
v0.0.1
Published
Passport strategy for authenticating with Annict using the OAuth 2.0 API.
Downloads
1
Readme
passport-annict
Passport strategy for authenticating with Annict using the OAuth 2.0 API.
Install
npm i passport-annict
Usage
passport.use(
new AnnictStrategy(
{
clientID: process.env.ANNICT_CLIENT_ID!,
clientSecret: process.env.ANNICT_CLIENT_SECRET!,
callbackURL: 'http://localhost:4000/login/callback',
scope: 'read write',
},
(_accessToken, _refreshToken, _result, profile, cb) => {
return cb(null, profile);
},
),
);
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
const app = Express();
app.use(session({ secret: process.env.SESSION_SECRET! }));
app.use(passport.initialize());
app.use(passport.session());
app.get('/login', passport.authenticate('annict'));
app.get('/login/callback', passport.authenticate('annict'), (_req, res) => {
res.redirect('/me');
});
app.get('/me', (req, res) => {
res.json(req.user);
});
app.listen(4000);
Contributing
PRs accepted.
License
MIT (c) 3846masa