passport-annict
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

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

Dependents (0)

Package Sidebar

Install

npm i passport-annict

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

7.19 kB

Total Files

9

Last publish

Collaborators

  • 3846masa