mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
27 lines
786 B
JavaScript
27 lines
786 B
JavaScript
const request = require('request');
|
|
|
|
module.exports = function () {
|
|
this.bindHook('third_login', (ctx) => {
|
|
let token = ctx.request.body.token || ctx.request.query.token;
|
|
console.log(token)
|
|
return new Promise((resolve, reject) => {
|
|
request('http://qsso.corp.qunar.com/api/verifytoken.php?token=' + token, function (error, response, body) {
|
|
if (!error && response.statusCode == 200) {
|
|
let result = JSON.parse(body);
|
|
if (result && result.ret === true) {
|
|
let ret = {
|
|
email: result.userId + '@qunar.com',
|
|
username: result.data.userInfo.name
|
|
};
|
|
resolve(ret);
|
|
} else {
|
|
reject(result);
|
|
}
|
|
}
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
)
|
|
} |