app.js
1.2 KB
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
'use strict';
const debug = require('debug')('egg-passport-dingtalk');
const assert = require('assert');
const Strategy = require('node-passport-dingtalk').Strategy;
module.exports = app => {
const config = app.config.passportDingtalk;
config.passReqToCallback = true;
assert(config.key, '[egg-passport-twitter] config.passportDingtalk.key required');
assert(config.secret, '[egg-passport-twitter] config.passportDingtalk.secret required');
config.clientID = config.key;
config.clientSecret = config.secret;
// must require `req` params
app.passport.use('dingtalk', new Strategy(config, (req, accessToken, refreshToken, results, profile, done) => {
// format user
const jsonInfo = profile._json || {};
const user = {
provider: 'dingtalk',
id: profile.id,
unionId:jsonInfo.unionId,
privateId:profile.privateId,
name: profile.name,
mobile: profile.mobile,
nick:jsonInfo.nick,
email:jsonInfo.email,
avatarUrl:jsonInfo.avatarUrl|| profile.headurl,
accessToken,
refreshToken,
results,
profile,
};
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);
}));
};