yapi/plugins/yapi-plugin-qsso/server.js
2017-09-06 10:18:13 +08:00

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);
});
});
}
)
}