passport-feishu2

0.0.2 • Public • Published

passport-feishu

Passport strategy for authenticating with Feishu.

To learn more details about Feishu's OAuth strategy, please refer to its online docs (English version, Chinese version).

This project is an imitation of Jared Hanson's works, such as passport-facebook and passport-google-oauth2.

Install

$ npm install passport-feishu2

Usage

Configure Strategy

const FeishuStrategy = require('passport-feishu').Strategy;

passport.use(new FeishuStrategy({
    clientID: FEISHU_APP_ID,
    clientSecret: FEISHU_APP_SECRET,
    callbackURL: "http://www.example.com/auth/feishu/callback",
    appType: "public",
    appTicket: function () {
        return new Promise((resolve, reject) => {
            setTimeout(function () {
                resolve("the-ticket-received-from-feishu-service")
            }, 1000)
        })
    }
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ feishuUserId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'feishu' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/feishu',
  passport.authenticate('feishu'));

app.get('/auth/feishu/callback', 
  passport.authenticate('feishu', { session: true, successReturnToOrRedirect: '/' })
);

License

The MIT License

Copyright (c) 2020 Jiamin Zhao

Package Sidebar

Install

npm i passport-feishu2

Weekly Downloads

7

Version

0.0.2

License

MIT

Unpacked Size

9.75 kB

Total Files

6

Last publish

Collaborators

  • tavenkim