Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize & extend #12

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"extends": "airbnb-base",
"parser": "babel-eslint",
"env": {
"node": true
},
"rules": {
"arrow-body-style": 0,
"consistent-return": 0,
"max-len": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-use-before-define": [2, "nofunc"],
"no-unused-expressions": 0,
"no-console": 0,
"space-before-function-paren": 0,
"no-restricted-syntax": 0,
"no-continue": 0,
"no-await-in-loop": 0,
"no-plusplus": 0,
"no-empty": ["error", { "allowEmptyCatch": true }],
"prefer-destructuring": ["warn", {
"VariableDeclarator": {
"array": false,
"object": true
},
"AssignmentExpression": {
"array": false,
"object": false
}
}]
},
"overrides": [{
"files": ["test/**/*.js"],
"env": {
"node": true,
"mocha": true
},
"rules": {
"func-names": 0,
"prefer-arrow-callback": 0,
"import/no-extraneous-dependencies": 0
}
}]
}

57 changes: 0 additions & 57 deletions .eslintrc.json

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules
npm-debug.log
.DS_store
.idea
.vscode
.gitignore
dist
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib
test
node_modules
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
8
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ends of SSO handshakes.

## Compatibility

Node 4+; Makes use of numerous ES6 features.
Node 8+; Makes use of numerous ES6 features and the new URL api

## Usage example - making an AuthnRequest as a service provider

Expand Down Expand Up @@ -94,12 +94,23 @@ return promises:

### ServiceProvider Methods

- `produceAuthnRequest(idpConfig)`: resolves to an object describing a request to the IDP, with either a post or redirect binding which is automatically selected based on the IDP's configuration. Contains the following properties:
- `produceAuthnRequest(idpConfig, options)`: resolves to an object describing a request to the IDP, with either a post or redirect binding which is automatically selected based on the IDP's configuration. Contains the following properties:
- `method`: either "POST" or "GET", indicating what flavor of HTTP request the user's browser should make to the IDP. The library automatically selects a post or redirect binding based on the IDP's configuration.
- `url`: a URL object indicating the URL to which the user should be sent, including query parameters for redirect bindings
- `contentType`: the content type to use when a post request is produced
- `formBody`: the form parameters to send in a post request to the IDP

The options for the request, see the [SAML2 core specification](http://saml.xml.org/saml-specifications) for more information:
- `isPassive`: sets the `IsPassive` boolean on the request. If `true`, the identity provider and the user agent itself MUST NOT visibly take control of the user interface from the requester and interact with the presenter in a noticeable fashion. If a value is not provided, the default is `false`.
- `forceAuthn`: sets the `ForceAuthN` boolean on the request. If `true`, the identity provider MUST authenticate the presenter directly rather than
rely on a previous security context. If a value is not provided, the default is `false`. However, if both
ForceAuthn and IsPassive are `true`, the identity provider MUST NOT freshly authenticate the
presenter unless the constraints of `IsPassive` can be met.
- `sendAuthnContext`: Wether to add the `RequestedAuthnContext` node to the request.
- `authnContextClassComparison`: Specifies the comparison method used to evaluate the requested context classes or statements, one
of `exact`, `minimum`, `maximum`, or `better`. The default is `exact`,
- `authnContextClasses`: Specifies one or more URI references identifying authentication context classes or declarations. The default is: `[PasswordProtectedTransport]`

- `consumePostResponse(formParams)`: accepts form parameters sent to an assertion post endpoint, and resolves to a description of the assertion or rejects with an error. In the event of success, will resolve the following properties:
- `idp`: the config for the IDP which sent the assertion
- `nameID`: the NameID sent in the assertion
Expand Down Expand Up @@ -151,3 +162,7 @@ return promises:
- `produceIDPMetadata()`: returns a string containing the IDP's XML metadata, the standard for passing configuration between SAML-supporting entities

- `getSPFromMetadata(xml)`: accepts an SP's XML metadata and produces a config object for use with this library


# additional notes
Currently we're blocked on XMLDOM 0.1.21 as a dependency because of: https://github.com/jindw/xmldom/pull/221
10 changes: 10 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const presets = [
['@babel/env', {
targets: {
node: '8',
},
useBuiltIns: 'usage',
}],
];

module.exports = { presets };
74 changes: 34 additions & 40 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
"use strict";
class SamlError extends Error {
constructor (message, sp, idp, payload) {
super(message);

this._sp = sp;
this._idp = idp;
this._payload = payload;
}

// add extended debug data in function bindings in case anyone's error
// handler tries to serialize one of these.
getSPn() {
return this._sp;
}

getIDP () {
return this._idp;
}

getPayload() {
return this._payload;
}
}

/**
* Errors thrown when one or more conditions invalidated an assertion
* or request. Groups an array of validation errors.
*/
class ValidationError extends Error {
constructor (message, errors, sp, idp, payload) {
super(message);

this.message = message;
this.errors = errors || [message];

// add extended debug data in function bindings in case anyone's error
// handler tries to serialize one of these.
this.getSP = function() { return sp; };
this.getIDP = function() { return idp; };
this.getPayload = function() { return payload; };
}
class ValidationError extends SamlError {
constructor (message, errors, sp, idp, payload) {
super(message, sp, idp, payload);
this.errors = errors || [message];
}
}

/**
* Errors thrown when an issue completely prevents the SAML protocol from
* functioning - primairly entity configuration.
*/
class ProtocolError extends Error {
constructor (message, sp, idp, payload) {
super(message);

// add extended debug data in function bindings in case anyone's error
// handler tries to serialize one of these.
this.getSP = function() { return sp; };
this.getIDP = function() { return idp; };
this.getPayload = function() { return payload; };
}
}
class ProtocolError extends SamlError {}

/**
* Thrown when an IDP rejects an auth request
*/
class RejectionError extends Error {
constructor(message, sp, idp, payload) {
super(message);

// add extended debug data in function bindings in case anyone's error
// handler tries to serialize one of these.
this.getSP = function() { return sp; };
this.getIDP = function() { return idp; };
this.getPayload = function() { return payload; };
}
}
class RejectionError extends SamlError {}

module.exports = {
ValidationError,
ProtocolError,
RejectionError
export {
ValidationError,
ProtocolError,
RejectionError,
};
Loading