Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
complete: function (request, reply) {
// Bell has obtained the oauth token, used it to get the profile, and
// that profile is available as request.auth.credentials.profile.
// Now, use it to set a cookie.
log.verbose('inside auth/complete');
log.verbose('request.auth.credentials is ' + JSON.stringify(request.auth.credentials));
// XXX temporary while we're in alpha: only allow whitelisted users, show
// a friendly error message if they're not on the list.
// TODO: on the front-end, auto-populate their email in a "want us to email you when
// we are adding new users?" form
if (!request.auth.credentials.profile.isAllowed) {
return reply(Boom.create(401, 'Sorry, only whitelisted users are allowed at this time.'));
}
var session = {
userId: request.auth.credentials.profile.userId
};
var duration = config.get('server_session_duration');
if (duration > 0) {
session.expiresAt = new Date(new Date().getTime() + duration);
}
request.auth.session.set(session);
if (request.auth.credentials.profile.isNewUser) {
reply.redirect('/#welcome');
} else {
reply.redirect('/');
}
bundle.action = action;
[err] = this.check('dispatch', bundle );
results = this.check('access', bundle );
err = err ? err : results[0];
if( err ){
return this.exception( annotate( err, bundle ) );
}
method = results[1];
if(this.throttle( bundle )){
return this.exception( annotate( Boom.create(429), bundle ) );
}
this.domain.run(() => {
let [err, result] = attempt(method, [bundle], this );
if( err ){
this.exception( annotate( err, bundle ) );
}
});
}
got.post('https://' + domain + '/login/oauth/access_token', options, function (err, body, response) {
if (err) {
if (err.statusCode === 404) {
return reply(Boom.create(err.statusCode, 'GitHub could not find client ID: \'' + client + '\''))
} else {
return reply(Boom.create(500, err))
}
} else {
if (body.error) {
return reply(Boom.create(400, body.error_description))
}
return reply(body)
}
})
}
server.inject(`/agent/${agentId}/domain/${domainId}`, (res) => {
if (res.statusCode !== 200){
if (res.statusCode === 404){
const errorNotFound = Boom.notFound('The specified domain doesn\'t exists in this agent');
return cb(errorNotFound);
}
const error = Boom.create(res.statusCode, 'An error occurred getting the data of the domain');
return cb(error, null);
}
domainName = res.result.domainName;
return cb(null);
});
},
server.inject(options, (res) => {
if (res.statusCode !== 200) {
const error = Boom.create(res.statusCode, `An error occurred updating the context ${elementInContext.id} of the session ${conversationStateObject.sessionId}`);
return callbackInsertInContext(error, null);
}
return callbackInsertInContext(null);
});
}
server.inject(`/agent/${agentId}`, (res) => {
if (res.statusCode !== 200){
if (res.statusCode === 404){
const errorNotFound = Boom.notFound('The specified agent doesn\'t exists');
return cb(errorNotFound);
}
const error = Boom.create(res.statusCode, 'An error occurred getting the data of the agent');
return cb(error, null);
}
return cb(null, res.result);
});
},
server.inject(`/domain/${domainId}`, (res) => {
if (res.statusCode !== 200){
if (res.statusCode === 404){
const error = Boom.notFound('The specified domain doesn\'t exists');
return cb(error, null);
}
const error = Boom.create(res.statusCode, 'An error occurred getting the domain');
return cb(error, null);
}
return cb(null);
});
},
buildError: function( code, error ){
return Boom.create( parseInt(code, 10), error);
},
server.inject(`/domain/${domainId}`, (res) => {
if (res.statusCode !== 200){
if (res.statusCode === 404){
const error = Boom.notFound('The specified domain doesn\'t exists');
return cb(error, null);
}
const error = Boom.create(res.statusCode, `An error occurred getting the data of the domain ${domainId}`);
return cb(error, null);
}
domain = res.result;
return cb(null);
});
},
server.inject('/agent/' + agentId, (res) => {
if (res.statusCode !== 200){
if (res.statusCode === 404){
const errorNotFound = Boom.notFound('The specified agent doesn\'t exists');
return cb(errorNotFound);
}
const error = Boom.create(res.statusCode, 'An error occurred getting the data of the agent');
return cb(error, null);
}
return cb(null);
});
},