New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

brightspace-auth-assertions

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brightspace-auth-assertions - npm Package Compare versions

Comparing version 2.0.2 to 6.0.0

24

package.json
{
"name": "brightspace-auth-assertions",
"version": "2.0.2",
"version": "6.0.0",
"description": "Require conditions are met by a Brigtspace JWT",
"repository": {
"type": "git",
"url": "https://github.com/Brightspace/node-auth-assertions.git"
},
"main": "src/index.js",
"scripts": {
"check-style": "jscs . && jshint .",
"test": "npm run check-style && mocha -R spec spec"
"test": "mocha -R spec spec"
},
"author": "D2L Corporation",
"bugs": {
"url": "https://github.com/Brightspace/node-auth/issues"
},
"homepage": "https://github.com/Brightspace/node-auth#readme",
"license": "Apache-2.0",
"devDependencies": {
"chai": "^2.1.0",
"jscs": "^1.11.3",
"jshint": "^2.6.3",
"mocha": "^2.1.0"
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/Brightspace/node-auth.git"
},
"dependencies": {
"brightspace-auth-token": "^3.1.1",
"inherits": "^2.0.1"
"brightspace-auth-token": "6.0.0"
}
}
# brightspace-auth-assertions
[![Build Status](https://magnum.travis-ci.com/Brightspace/node-auth-assertions.svg?token=M9m6audKHodN5pA44rGq&branch=master)](https://magnum.travis-ci.com/Brightspace/node-auth-assertions)
[![Build Status](https://travis-ci.org/Brightspace/node-auth.svg?branch=master)](https://travis-ci.org/Brightspace/node-auth)
## Example

@@ -13,3 +14,4 @@

.scope('valance', 'apps', 'manage').require()
.context(AssertionCompiler.contexts.Tenant).require()
.context(AssertionCompiler.contexts.User).require()
.impersonation().reject()
.compile();

@@ -27,33 +29,1 @@

```
## Testing
```bash
npm test
```
## Contributing
1. **Fork** the repository. Committing directly against this repository is
highly discouraged.
2. Make your modifications in a branch, updating and writing new unit tests
as necessary in the `spec` directory.
3. Ensure that all tests pass with `npm test`
4. `rebase` your changes against master. *Do not merge*.
5. Submit a pull request to this repository. Wait for tests to run and someone
to chime in.
### Code Style
This repository is configured with [EditorConfig][EditorConfig], [jscs][jscs]
and [JSHint][JSHint] rules. See the [docs.dev code style article][code style]
for information on installing editor extensions.
[EditorConfig]: http://editorconfig.org/
[jscs]: http://jscs.info/
[JSHint]: http://jshint.com/
[code style]: http://docs.dev.d2l/index.php/JavaScript_Code_Style_(Personal_Learning)

@@ -5,3 +5,3 @@ 'use strict';

function InvalidContextError () {
function InvalidContextError() {
this.name = 'InvalidContextError';

@@ -15,3 +15,3 @@ this.status = 403;

function InsufficientScopeError (group, resource, permission) {
function InsufficientScopeError(group, resource, permission) {
this.name = 'InsufficientScopeError';

@@ -25,5 +25,25 @@ this.status = 403;

function ImpersonationNotAllowedError(user, actualUser) {
this.name = 'ImpersonationNotAllowedError';
this.status = 403;
this.message = `Impersonation is not allowed, but user (${user}) and actual user (${actualUser}) differ.`;
Error.captureStackTrace(this, this.constructor);
}
inherits(ImpersonationNotAllowedError, Error);
function ImpersonationRequiredError() {
this.name = 'ImpersonationRequiredError';
this.status = 403;
this.message = 'Impersonation is required.';
Error.captureStackTrace(this, this.constructor);
}
inherits(ImpersonationRequiredError, Error);
module.exports = {
InvalidContext: InvalidContextError,
InsufficientScope: InsufficientScopeError
InsufficientScope: InsufficientScopeError,
ImpersonationNotAllowed: ImpersonationNotAllowedError,
ImpersonationRequired: ImpersonationRequiredError
};
'use strict';
const
AuthToken = require('brightspace-auth-token'),
inherits = require('inherits');
const AuthToken = require('brightspace-auth-token');
const inherits = require('util').inherits;
const errors = require('./errors');
function AssertionCompiler () {
function AssertionCompiler() {
if (!(this instanceof AssertionCompiler)) {

@@ -17,3 +16,3 @@ return new AssertionCompiler();

AssertionCompiler.prototype.scope = function addScopeAssertion (broad, narrow, permission) {
AssertionCompiler.prototype.scope = function addScopeAssertion(broad, narrow, permission) {
const assertion = new ScopeAssertion(this, broad, narrow, permission);

@@ -23,3 +22,3 @@ return assertion;

AssertionCompiler.prototype.context = function addContextAssertion (context) {
AssertionCompiler.prototype.context = function addContextAssertion(context) {
const assertion = new ContextAssertion(this, context);

@@ -29,6 +28,11 @@ return assertion;

AssertionCompiler.prototype.compile = function compileAssertions () {
AssertionCompiler.prototype.impersonation = function addImpersontationAssertion() {
const assertion = new ImpersonationAssertion(this);
return assertion;
};
AssertionCompiler.prototype.compile = function compileAssertions() {
const assertions = this._assertions.slice();
return function compiledAassertion (token) {
for (let assertion of assertions) {
return function compiledAassertion(token) {
for (const assertion of assertions) {
assertion.assert(token);

@@ -39,3 +43,3 @@ }

function AuthAssertion (compiler) {
function AuthAssertion(compiler) {
if (!(this instanceof AuthAssertion)) {

@@ -54,3 +58,3 @@ return new AuthAssertion(compiler);

AuthAssertion.prototype._inject = function injectAssertion () {
AuthAssertion.prototype._inject = function injectAssertion() {
this._compiler._assertions.push(this);

@@ -61,3 +65,3 @@

AuthAssertion.prototype.require = function requireAssertion () {
AuthAssertion.prototype.require = function requireAssertion() {
this._required = true;

@@ -72,3 +76,3 @@

AuthAssertion.prototype.reject = function rejectAssertion () {
AuthAssertion.prototype.reject = function rejectAssertion() {
this._rejected = true;

@@ -83,3 +87,3 @@

AuthAssertion.prototype.assert = function assertAssertion (token) {
AuthAssertion.prototype.assert = function assertAssertion(token) {
if ('function' === typeof this._assert) {

@@ -90,3 +94,3 @@ this._assert(token);

function ScopeAssertion (compiler, broad, narrow, permission) {
function ScopeAssertion(compiler, broad, narrow, permission) {
AuthAssertion.call(this, compiler);

@@ -100,4 +104,4 @@

ScopeAssertion.prototype._assert = function assertScope (token) {
let matched = token.hasScope(this.broad, this.narrow, this.permission);
ScopeAssertion.prototype._assert = function assertScope(token) {
const matched = token.hasScope(this.broad, this.narrow, this.permission);

@@ -109,7 +113,7 @@ if (!matched) {

ScopeAssertion.prototype._reject = function rejectScope () {
ScopeAssertion.prototype._reject = function rejectScope() {
throw new Error('Rejecting a scope makes no sense');
};
function ContextAssertion (compiler, context) {
function ContextAssertion(compiler, context) {
AuthAssertion.call(this, compiler);

@@ -121,3 +125,3 @@

ContextAssertion.prototype._assert = function assertContext (token) {
ContextAssertion.prototype._assert = function assertContext(token) {
let matched = false;

@@ -145,4 +149,23 @@

function ImpersonationAssertion(compiler) {
AuthAssertion.call(this, compiler);
}
inherits(ImpersonationAssertion, AuthAssertion);
ImpersonationAssertion.prototype._require = function requireImpersonation() {
new ContextAssertion(this._compiler, AuthToken.contexts.User).require();
};
ImpersonationAssertion.prototype._assert = function assertImpersontation(token) {
if (this._required) {
if (!token.isImpersonating()) {
throw new errors.ImpersonationRequired();
}
} else if (/* this._rejected && */token.isImpersonating()) {
throw new errors.ImpersonationNotAllowed(token.user, token.actualUser);
}
};
module.exports = AssertionCompiler;
module.exports.contexts = AuthToken.contexts;
module.exports.errors = errors;
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