Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kazana-account

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kazana-account - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

LICENSE

6

index.js

@@ -1,7 +0,7 @@

var sessionRoutes = require('./lib/routes/session');
var sessionRoutes = require('./lib/routes/session')
module.exports = {
name: 'account',
version: '1.0.0',
version: require('./package').version,
routes: sessionRoutes
};
}

@@ -1,8 +0,8 @@

var _ = require('lodash');
var Boom = require('boom');
var Wreck = require('wreck');
var _ = require('lodash')
var Boom = require('boom')
var Wreck = require('wreck')
var addUserId = require('../../utils/add-user-id');
var mapSessionRequest = require('../../utils/map-session-request');
var loadUserDocProperties = require('../../utils/load-user-doc-properties');
var addUserId = require('../../utils/add-user-id')
var mapSessionRequest = require('../../utils/map-session-request')
var loadUserDocProperties = require('../../utils/load-user-doc-properties')

@@ -20,5 +20,6 @@ module.exports = {

onResponse: function (error, response, request, reply) {
if (error) return reply.pouchdbError(error);
/* istanbul ignore if */
if (error) return reply.pouchdbError(error)
var server = request.connection.server;
var server = request.connection.server

@@ -28,23 +29,26 @@ Wreck.read(response, {

}, function (error, data) {
if (error) return reply.pouchdbError(error);
/* istanbul ignore if */
if (error) return reply.pouchdbError(error)
/* istanbul ignore if */
if (response.statusCode >= 300) {
return reply.pouchdbError(data);
return reply.pouchdbError(data)
}
if (!data.userCtx.name) {
return reply(Boom.notFound());
return reply(Boom.notFound())
}
data = addUserId(data);
data = addUserId(data)
loadUserDocProperties(server, data.userCtx.name, function (error, properties) {
if (error) return reply.pouchdbError(error);
/* istanbul ignore if */
if (error) return reply.pouchdbError(error)
_.merge(data.userCtx, properties);
reply(data);
});
});
_.merge(data.userCtx, properties)
reply(data)
})
})
}
}
}
};
}

@@ -5,2 +5,2 @@ module.exports = [

require('./sign-out')
];
]

@@ -1,3 +0,3 @@

var addBearerToken = require('../../utils/add-bearer-token');
var mapSessionRequest = require('../../utils/map-session-request');
var addBearerToken = require('../../utils/add-bearer-token')
var mapSessionRequest = require('../../utils/map-session-request')

@@ -7,2 +7,5 @@ module.exports = {

path: '/api/session',
config: {
auth: false
},
handler: {

@@ -14,6 +17,3 @@ proxy: {

}
},
config: {
auth: false
}
};
}

@@ -1,3 +0,3 @@

var mapSessionRequest = require('../../utils/map-session-request');
var removeCookie = require('../../utils/remove-cookie');
var mapSessionRequest = require('../../utils/map-session-request')
var removeCookie = require('../../utils/remove-cookie')

@@ -17,2 +17,2 @@ module.exports = {

}
};
}

@@ -1,13 +0,14 @@

module.exports = addBearerToken;
module.exports = addBearerToken
var Wreck = require('wreck');
var _ = require('lodash');
var Wreck = require('wreck')
var _ = require('lodash')
var cookieToToken = require('./cookie-to-token');
var addUserIdAndAgency = require('./add-user-id');
var loadUserDocProperties = require('./load-user-doc-properties');
var cookieToToken = require('./cookie-to-token')
var addUserIdAndAgency = require('./add-user-id')
var loadUserDocProperties = require('./load-user-doc-properties')
function addBearerToken (error, response, request, reply) {
var server = request.connection.server;
if (error) return reply(error).code(500);
var server = request.connection.server
/* istanbul ignore if */
if (error) return reply(error).code(500)

@@ -17,22 +18,25 @@ Wreck.read(response, {

}, function (error, data) {
if (error) return reply(error).code(500);
/* istanbul ignore if */
if (error) return reply(error).code(500)
if (Array.isArray(response.headers['set-cookie'])) {
data.bearerToken = cookieToToken(response.headers['set-cookie']);
delete response.headers['set-cookie'];
data.bearerToken = cookieToToken(response.headers['set-cookie'])
delete response.headers['set-cookie']
}
/* istanbul ignore if */
if (response.statusCode >= 300) {
return reply(data).code(response.statusCode);
return reply(data).code(response.statusCode)
}
data = addUserIdAndAgency(data);
data = addUserIdAndAgency(data)
loadUserDocProperties(server, data.name, function (error, properties) {
if (error) return reply(error).code(500);
/* istanbul ignore if */
if (error) return reply(error).code(500)
_.merge(data, properties);
reply(data).code(response.statusCode);
});
});
_.merge(data, properties)
reply(data).code(response.statusCode)
})
})
}

@@ -1,53 +0,28 @@

module.exports = addUserIdToSessionResponse;
module.exports = addUserId
// turns
// {
// "ok": true,
// "userCtx": {
// "name": "test-admin@example.com",
// "roles": [
// "kazana-id:testadmin",
// "kazana-data-provider",
// "kazana-data-reviewer",
// "kazana-analyst",
// "kazana-admin"
// ]
// },
// }
// into
// {
// "ok": true,
// "userCtx": {
// "name": "test-admin@example.com",
// "roles": [
// "kazana-data-provider",
// "kazana-data-reviewer",
// "kazana-analyst",
// "kazana-admin"
// ]
// },
// "id": "testadmin"
// }
function addUserIdToSessionResponse (response) {
var userCtx = response.userCtx || response;
var roles = userCtx.roles;
function addUserId (response) {
var userCtx = response.userCtx || response
var roles = userCtx.roles
if (!roles || roles.length === 0) {
return response;
if (!roles) {
return response
}
var idRoleIndex;
var id;
var idRoleIndex
var id
roles.forEach(function (name, i) {
if (name.indexOf('kazana-id:') === 0) {
idRoleIndex = i;
id = name.substr('kazana-id:'.length);
idRoleIndex = i
id = name.substr('kazana-id:'.length)
}
});
})
if (typeof idRoleIndex !== 'undefined') {
roles.splice(idRoleIndex, 1);
roles.splice(idRoleIndex, 1)
}
userCtx.id = id;
return response;
if (id) {
userCtx.id = id
}
return response
}

@@ -1,8 +0,8 @@

module.exports = cookieToToken;
module.exports = cookieToToken
function cookieToToken (cookieHeader) {
var result = (/AuthSession=([^;]+);/).exec(cookieHeader[0]);
var result = (/AuthSession=([^;]+);/).exec(cookieHeader[0])
if (Array.isArray(result)) {
return result[1];
return result[1]
}
}

@@ -1,2 +0,2 @@

module.exports = loadUserDocProperties;
module.exports = loadUserDocProperties

@@ -7,3 +7,3 @@ function loadUserDocProperties (server, login, callback) {

auth: 'admin'
});
})

@@ -15,5 +15,5 @@ store.find('org.couchdb.user:' + login)

createdAt: userDoc.createdAt
});
})
})
.catch(callback);
.catch(callback)
}

@@ -1,27 +0,28 @@

module.exports = mapSessionRequest;
module.exports = mapSessionRequest
var requestToToken = require('./request-to-token');
var url = require('url');
var requestToToken = require('./request-to-token')
var url = require('url')
function mapSessionRequest (request, callback) {
var server = request.connection.server;
var server = request.connection.server
var urlParts = url.parse(server.methods.getCouchUrl());
var port = urlParts.port ? ':' + urlParts.port : '';
var baseUrl = urlParts.protocol + '//' + urlParts.hostname + port;
var urlParts = url.parse(server.methods.getCouchUrl())
/* istanbul ignore next */
var port = urlParts.port ? ':' + urlParts.port : ''
var baseUrl = urlParts.protocol + '//' + urlParts.hostname + port
var options = {
baseUrl: baseUrl,
host: urlParts.host
};
}
// use the bearer token as the cookie AuthSession for couchdb:
var token = requestToToken(request);
var token = requestToToken(request)
if (token) {
request.headers.cookie = 'AuthSession=' + token;
request.headers.cookie = 'AuthSession=' + token
} else {
delete request.headers.cookie;
delete request.headers.cookie
}
request.host = options.host;
callback(null, options.baseUrl + '/_session', request.headers);
request.host = options.host
callback(null, options.baseUrl + '/_session', request.headers)
}

@@ -1,7 +0,8 @@

module.exports = removeCookie;
module.exports = removeCookie
var Wreck = require('wreck');
var Wreck = require('wreck')
function removeCookie (error, res, request, reply) {
if (error) return reply(error).code(500);
/* istanbul ignore if */
if (error) return reply(error).code(500)

@@ -11,5 +12,6 @@ Wreck.read(res, {

}, function (error, data) {
if (error) return reply(error).code(500);
/* istanbul ignore if */
if (error) return reply(error).code(500)
delete res.headers['set-cookie'];
delete res.headers['set-cookie']

@@ -20,10 +22,11 @@ // weird malform cookie issue

// that needs to be invalidated in the client
/* istanbul ignore if */
if (res.statusCode === 400) {
return reply({
ok: true
}).code(200);
}).code(200)
}
reply(data).code(res.statusCode);
});
reply(data).code(res.statusCode)
})
}

@@ -1,9 +0,9 @@

module.exports = requestToToken;
module.exports = requestToToken
function requestToToken (request) {
var token;
var token
if (request.headers.authorization) {
token = request.headers.authorization.substring('Bearer '.length);
token = request.headers.authorization.substring('Bearer '.length)
}
return token;
return token
}
{
"name": "kazana-account",
"description": "Kazana core module for all things accounts and authentication",
"version": "2.0.1",
"main": "index.js",
"scripts": {
"start": "kazana --bare",
"test": "semistandard && npm run test:node | tap-spec",
"test:coverage": "istanbul cover tests",
"test:coverage:upload": "istanbul-coveralls",
"test:node": "node tests",
"pretest": "standard",
"test": "tap --coverage tests/**/*-test.js",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"

@@ -26,23 +25,27 @@ },

"homepage": "https://github.com/eHealthAfrica/kazana-account",
"engines": {
"node": ">=4.2.0",
"npm": ">=2.14.0"
},
"dependencies": {
"boom": "^2.8.0",
"hoek": "^2.14.0",
"joi": "^6.6.1",
"boom": "^3.0.0",
"hoek": "^3.0.4",
"joi": "^7.0.0",
"lodash": "^3.10.1",
"wreck": "^6.1.0"
"wreck": "^7.0.0"
},
"devDependencies": {
"h2o2": "^4.0.1",
"hapi": "^9.0.1",
"istanbul": "^0.3.17",
"istanbul-coveralls": "^1.0.3",
"kazana": "^2.0.0",
"lie": "^3.0.1",
"nock": "^2.10.0",
"semantic-release": "^4.0.3",
"semistandard": "^7.0.2",
"tap-spec": "^4.0.2",
"tape": "^4.1.0"
"kazana-server": "^3.9.7",
"request": "^2.67.0",
"semantic-release": "^6.0.3",
"standard": "^5.4.1",
"tap": "^5.0.0"
},
"version": "2.0.0"
}
"config": {
"nyc": {
"exclude": [
"tests/**/*"
]
}
}
}

@@ -102,2 +102,2 @@ # kazana-account

Apache-2.0
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc