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

a12n-server

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a12n-server - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

dist/privilege/types.d.ts

10

changelog.md
Changelog
=========
0.6.0 (2019-07-30)
------------------
* Added a registration form
* Added a simple settings system.
* Now using `@curveball/problem` for error handling.
* Added support for resource-specific privileges, allowing users to store
privileges based on arbitrary urls.
0.5.0 (2019-05-02)

@@ -5,0 +15,0 @@ ------------------

32

dist/app.js

@@ -6,18 +6,24 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable no-console
const core_1 = require("@curveball/core");
const process_1 = __importDefault(require("process"));
const main_mw_1 = __importDefault(require("./main-mw"));
const app = new core_1.Application();
app.use(async (ctx, next) => {
// tslint:disable-next-line:no-console
console.log('=> %s %s', ctx.request.method, ctx.request.path);
await next();
// tslint:disable-next-line:no-console
console.log('<= %s', ctx.response.status);
});
app.use(main_mw_1.default());
const port = process_1.default.env.PORT ? parseInt(process_1.default.env.PORT, 10) : 8531;
app.listen(port);
// tslint:disable-next-line:no-console
console.log('Listening on port', port);
const server_settings_1 = require("./server-settings");
(async () => {
const pkgInfo = require('../package.json');
console.log('%s %s', pkgInfo.name, pkgInfo.version);
console.log('Connecting to database');
console.log('Loading settings');
await server_settings_1.load();
const app = new core_1.Application();
app.use(async (ctx, next) => {
console.log('=> %s %s', ctx.request.method, ctx.request.path);
await next();
console.log('<= %s', ctx.response.status);
});
app.use(main_mw_1.default());
const port = process_1.default.env.PORT ? parseInt(process_1.default.env.PORT, 10) : 8531;
app.listen(port);
console.log('Listening on port', port);
})();
//# sourceMappingURL=app.js.map

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

declare const _default: (version: string) => {
_links: {
'self': {
href: string;
title: string;
};
'sa:authorize': {
href: string;
title: string;
type: string;
};
'sa:logout': {
href: string;
title: string;
};
'sa:token': {
href: string;
title: string;
};
'sa:validate-bearer': {
href: string;
title: string;
};
'sa:validate-totp': {
href: string;
title: string;
};
'sa:user-collection': {
href: string;
title: string;
};
'oauth_server_metadata_uri': {
href: string;
title: string;
};
};
version: string;
};
import { HalBody } from '../../types';
declare const _default: (version: string) => HalBody;
export default _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = (version) => ({
_links: {
'self': { href: '/', title: 'Auth API Home' },
'sa:authorize': { href: '/authorize', title: 'OAuth2 authorize endpoint', type: 'text/html' },
'sa:logout': { href: '/logout', title: 'Expire tokens and sessions' },
'sa:token': { href: '/token', title: 'OAuth2 protocol endpoint' },
'sa:validate-bearer': { href: '/validate-bearer', title: 'Validate a OAuth2 bearer token' },
'sa:validate-totp': { href: '/validate-totp', title: 'Validate a TOTP 2FA token + bearer token' },
'sa:user-collection': { href: '/user', title: 'List of users' },
'oauth_server_metadata_uri': { href: '/.well-known/oauth-authorization-server', title: 'OAuth 2.0 Authorization Server Metadata' }
},
version: version,
});
const server_settings_1 = require("../../server-settings");
exports.default = (version) => {
const result = {
_links: {
'self': { href: '/', title: 'Auth API Home' },
'sa:authorize': { href: '/authorize', title: 'OAuth2 authorize endpoint', type: 'text/html' },
'sa:logout': { href: '/logout', title: 'Expire tokens and sessions' },
'sa:token': { href: '/token', title: 'OAuth2 protocol endpoint' },
'sa:validate-bearer': { href: '/validate-bearer', title: 'Validate a OAuth2 bearer token' },
'sa:validate-totp': { href: '/validate-totp', title: 'Validate a TOTP 2FA token + bearer token' },
'sa:user-collection': { href: '/user', title: 'List of users' },
'oauth_server_metadata_uri': { href: '/.well-known/oauth-authorization-server', title: 'OAuth 2.0 Authorization Server Metadata' }
},
version: version,
};
if (server_settings_1.getSetting('registration.enabled')) {
result._links['sa:registration'] = {
href: '/registration',
title: 'Create a new user account'
};
}
return result;
};
//# sourceMappingURL=hal.js.map

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

import mw from './main-mw';
export default mw;
/**
* If this package is used as a dependency, this package
* exposes a middleware for curveball, and a load function that
* needs to be called to initialize the server
*/
export { default as mainMw } from './main-mw';
export { load as init } from './server-settings';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const main_mw_1 = __importDefault(require("./main-mw"));
exports.default = main_mw_1.default;
/**
* If this package is used as a dependency, this package
* exposes a middleware for curveball, and a load function that
* needs to be called to initialize the server
*/
var main_mw_1 = require("./main-mw");
exports.mainMw = main_mw_1.default;
var server_settings_1 = require("./server-settings");
exports.init = server_settings_1.load;
//# sourceMappingURL=index.js.map

@@ -8,6 +8,6 @@ "use strict";

const core_1 = require("@curveball/core");
const problem_1 = __importDefault(require("@curveball/problem"));
const session_1 = __importDefault(require("@curveball/session"));
const hal_browser_1 = __importDefault(require("hal-browser"));
const login_1 = __importDefault(require("./middleware/login"));
const problem_1 = __importDefault(require("./middleware/problem"));
const routes_1 = __importDefault(require("./routes"));

@@ -14,0 +14,0 @@ function default_1() {

@@ -7,2 +7,3 @@ "use strict";

'/health',
'/register',
'/authorize',

@@ -9,0 +10,0 @@ '/token',

import { User } from '../user/types';
export declare function getPrivilegesForUser(user: User): Promise<string[]>;
export declare function hasPrivilege(user: User, privilege: string): Promise<boolean>;
import { PrivilegeMap } from './types';
export declare function getPrivilegesForUser(user: User): Promise<PrivilegeMap>;
export declare function hasPrivilege(user: User, scope: string, resource: string): Promise<boolean>;

@@ -8,12 +8,21 @@ "use strict";

async function getPrivilegesForUser(user) {
const query = 'SELECT privilege FROM user_privileges WHERE user_id = ?';
const query = 'SELECT resource, scope FROM user_privileges WHERE user_id = ?';
const result = await database_1.default.query(query, [user.id]);
return result[0].map((row) => {
return row.privilege;
});
return result[0].reduce((currentPrivileges, row) => {
const privileges = Object.assign({}, currentPrivileges);
if (privileges.hasOwnProperty(row.resource)) {
if (privileges[row.resource].indexOf(row.scope) === -1) {
privileges[row.resource].push(row.scope);
}
}
else {
privileges[row.resource] = [row.scope];
}
return privileges;
}, {});
}
exports.getPrivilegesForUser = getPrivilegesForUser;
async function hasPrivilege(user, privilege) {
const query = 'SELECT id FROM user_privileges WHERE user_id = ? AND privilege = ?';
const result = await database_1.default.query(query, [user.id, privilege]);
async function hasPrivilege(user, scope, resource) {
const query = 'SELECT id FROM user_privileges WHERE user_id = ? AND scope = ? AND resource = ?';
const result = await database_1.default.query(query, [user.id, scope, resource]);
return result[0].length === 1;

@@ -20,0 +29,0 @@ }

@@ -18,2 +18,3 @@ "use strict";

const validate_totp_1 = __importDefault(require("./oauth2/controller/validate-totp"));
const controller_6 = __importDefault(require("./register/controller"));
const collection_1 = __importDefault(require("./user/controller/collection"));

@@ -29,2 +30,3 @@ const item_1 = __importDefault(require("./user/controller/item"));

router_1.default('/health', controller_2.default),
router_1.default('/register', controller_6.default),
router_1.default('/authorize', authorize_1.default),

@@ -31,0 +33,0 @@ router_1.default('/validate-bearer', validate_bearer_1.default),

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

import { PrivilegeMap } from '../../privilege/types';
import { User } from '../types';
export declare function collection(users: User[]): any;
export declare function item(user: User, privileges: string[]): any;
export declare function item(user: User, privileges: PrivilegeMap): any;

@@ -6,2 +6,3 @@ import { NewUser, User } from './types';

export declare function save(user: User | NewUser): Promise<User>;
export declare function createPassword(user: User, password: string): Promise<void>;
/**

@@ -8,0 +9,0 @@ * Returns true or false if the password was correct.

@@ -76,2 +76,10 @@ "use strict";

exports.save = save;
async function createPassword(user, password) {
const query = 'INSERT INTO user_passwords SET user_id = ?, password = ?';
await database_1.default.query(query, [
user.id,
await bcrypt_1.default.hash(password, 12)
]);
}
exports.createPassword = createPassword;
/**

@@ -78,0 +86,0 @@ * Returns true or false if the password was correct.

{
"name": "a12n-server",
"version": "0.5.0",
"version": "0.6.0",
"main": "dist/index.js",

@@ -29,15 +29,14 @@ "description": "A ready-to-launch User and Authentication system for those that don't want to build it",

"@types/chai": "^4.1.7",
"@types/csv-stringify": "^1.4.3",
"@types/handlebars": "^4.1.0",
"@types/mocha": "^5.2.6",
"@types/node": "^11.13.8",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.8",
"@types/otplib": "^7.0.0",
"@types/sinon": "^7.0.11",
"@types/sinon": "^7.0.13",
"chai": "^4.2.0",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"sinon": "^7.3.2",
"ts-node": "^8.1.0",
"tslint": "^5.16.0",
"typescript": "^3.4.5"
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"typescript": "^3.5.3"
},

@@ -51,16 +50,15 @@ "types": "dist/",

"dependencies": {
"@curveball/bodyparser": "^0.4.0",
"@curveball/bodyparser": "^0.4.1",
"@curveball/controller": "^0.1.0",
"@curveball/core": "^0.8.6",
"@curveball/http-errors": "^0.3.0",
"@curveball/problem": "^0.1.0",
"@curveball/router": "^0.2.1",
"@curveball/session": "^0.3.2",
"bcrypt": "^3.0.6",
"csv-stringify": "^5.3.0",
"hal-browser": "^0.7.3",
"hal-browser": "^0.7.4",
"handlebars": "^4.1.2",
"moment": "^2.24.0",
"mysql2": "^1.6.5",
"otplib": "^11.0.0"
"otplib": "^11.0.1"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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