-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (34 loc) · 1.15 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const debug = require('debug')('egg-passport-feishu');
const assert = require('assert');
const Strategy = require('./lib').Strategy;
module.exports = app => {
const config = app.config.passportFeishu;
config.passReqToCallback = true;
assert(config.key, '[egg-passport-feishu] config.passportFeishu.key required');
assert(config.secret, '[egg-passport-feishu] config.passportFeishu.secret required');
config.clientID = config.key;
config.clientSecret = config.secret;
config.appType = config.appType;
// must require `req` params
app.passport.use('feishu', new Strategy(config, (req, accessToken, refreshToken, profile, done) => {
// format user
const user = {
provider: 'feishu',
id: profile.id,
name: profile.mobile,
displayName: profile.name,
photo: profile.avatar.icon,
accessToken,
refreshToken,
// params,
profile,
};
if (profile.email) {
user.emails = [{ value: profile.email }];
}
// debug('%s %s get user: %j', req.method, req.url, user);
// let passport do verify and call verify hook
app.passport.doVerify(req, user, done);
}));
};