login.js
820 Bytes
const Service = require('egg').Service;
class LoginService extends Service {
async localLogin(user,access_token='') {
const { ctx, config={}, app, logger } = this;
const { restful={} } = config;
const { host, port, tokenUrl,tokenMethod} = restful;
const result = await ctx.curl(`${host}:${port}${tokenUrl}`, {
method: `${tokenMethod}`,
dataType: 'json',
data: JSON.stringify(ctx.request.body),
headers: {
'authorization': `Bearer ${access_token}`,
'accept': 'application/json',
'content-type': 'application/json'
},
timeout: [5000, 60000]
});
ctx.session.user_info = result.data;
return result;
}
}
module.exports = LoginService;