passport-saml-metadata
Advanced tools
Comparing version 2.0.1 to 2.1.0
# Change Log | ||
## [v2.0.1](https://github.com/compwright/passport-saml-metadata/tree/v2.0.1) (2019-08-17) | ||
[Full Changelog](https://github.com/compwright/passport-saml-metadata/compare/v2.0.0...v2.0.1) | ||
## [v2.0.0](https://github.com/compwright/passport-saml-metadata/tree/v2.0.0) (2019-08-17) | ||
@@ -24,2 +27,3 @@ [Full Changelog](https://github.com/compwright/passport-saml-metadata/compare/v1.6.0...v2.0.0) | ||
- Update superagent to the latest version 🚀 [\#10](https://github.com/compwright/passport-saml-metadata/pull/10) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) | ||
- toPassportConfig: use entryPoint for passport-saml [\#1](https://github.com/compwright/passport-saml-metadata/pull/1) ([leachiM2k](https://github.com/leachiM2k)) | ||
@@ -66,3 +70,2 @@ ## [v1.5.2](https://github.com/compwright/passport-saml-metadata/tree/v1.5.2) (2018-09-11) | ||
- Updating Dependencies \(\#2\) [\#3](https://github.com/compwright/passport-saml-metadata/pull/3) ([TigerC10](https://github.com/TigerC10)) | ||
- toPassportConfig: use entryPoint for passport-saml [\#1](https://github.com/compwright/passport-saml-metadata/pull/1) ([leachiM2k](https://github.com/leachiM2k)) | ||
@@ -69,0 +72,0 @@ ## [v1.3.0](https://github.com/compwright/passport-saml-metadata/tree/v1.3.0) (2018-02-05) |
{ | ||
"name": "passport-saml-metadata", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "SAML2 metadata loader", | ||
@@ -61,6 +61,6 @@ "author": { | ||
"dependencies": { | ||
"axios": "^0.19.0", | ||
"debug": "^4.1.1", | ||
"lodash": "^4.17.15", | ||
"passport-saml": "^1.1.0", | ||
"superagent": "^5.1.0", | ||
"xmldom": "^0.1.27", | ||
@@ -70,2 +70,3 @@ "xpath": "0.0.27" | ||
"devDependencies": { | ||
"axios-mock-adapter": "^1.17.0", | ||
"eslint": "^6.1.0", | ||
@@ -72,0 +73,0 @@ "mocha": "^6.2.0", |
# passport-saml-metadata | ||
[![Build Status](https://travis-ci.org/compwright/passport-saml-metadata.svg?branch=master)](https://travis-ci.org/compwright/passport-saml-metadata) [![Greenkeeper badge](https://badges.greenkeeper.io/compwright/passport-saml-metadata.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/compwright/passport-saml-metadata.svg?branch=master)](https://travis-ci.org/compwright/passport-saml-metadata) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/compwright/passport-saml-metadata.svg)](https://greenkeeper.io/) | ||
@@ -55,2 +56,3 @@ Utilities for reading configuration from SAML 2.0 Metadata XML files, such as those generated by Active Directory Federation Services (ADFS). | ||
* `client` [Axios](https://www.npmjs.com/package/axios) instance | ||
* `url` (required) Metadata XML file URL | ||
@@ -60,2 +62,4 @@ * `timeout` Time to wait before falling back to the `backupStore`, in ms (default = `2000`) | ||
Additional configuration options supported: https://github.com/axios/axios#request-config | ||
Returns a promise which resolves, if successful, to an instance of `MetadataReader`. | ||
@@ -62,0 +66,0 @@ |
const assert = require('assert'); | ||
const request = require('superagent'); | ||
const axios = require('axios'); | ||
const debug = require('debug')('passport-saml-metadata'); | ||
const defaults = { | ||
client: axios, | ||
responseType: 'text', | ||
timeout: 2000, | ||
@@ -10,4 +12,9 @@ backupStore: new Map() | ||
module.exports = (config = {}) => { | ||
const { url, timeout, backupStore } = Object.assign({}, defaults, config); | ||
module.exports = async function(config = {}) { | ||
const { | ||
client, | ||
url, | ||
backupStore, | ||
...params | ||
} = Object.assign({}, defaults, config); | ||
@@ -19,37 +26,37 @@ assert.ok(url, 'url is required'); | ||
debug('Loading metadata', url, timeout, backupStore); | ||
debug('Loading metadata', url, params.timeout, backupStore); | ||
return request.get(url) | ||
.timeout(timeout) | ||
.buffer(true) | ||
.then((res) => { | ||
debug('Metadata loaded', res.text.length); | ||
backupStore.set(url, res.text); | ||
return res.text; | ||
}) | ||
.catch((err) => { | ||
let error = err; | ||
try { | ||
const res = await client.get(url, params); | ||
debug('Metadata loaded', res.headers['content-length']); | ||
backupStore.set(url, res.data); // Save in backup store | ||
return res.data; | ||
} catch (err) { | ||
let error; | ||
if (err.response) { | ||
error = new Error(err.response.data); | ||
error.status = err.response.status; | ||
} else if (err.request) { | ||
error = new Error('Error during request, no response'); | ||
} else { | ||
error = err; | ||
} | ||
// Superagent emits errors with error.response instead of error.message | ||
if (err.response) { | ||
error = err.response.error || new Error(err.response.body.message); | ||
error.status = err.response.status; | ||
debug('Metadata request failed, attempting backup store', error); | ||
try { | ||
// Try from backup store | ||
const data = await Promise.resolve(backupStore.get(url)); | ||
if (data) { | ||
debug('Metadata loaded from backupStore', data.length); | ||
return data; | ||
} else { | ||
debug('Backup store was empty'); | ||
throw error; | ||
} | ||
debug('Metadata request failed, attempting backup store', err); | ||
return Promise.resolve(backupStore.get(url)) | ||
.then((data) => { | ||
if (!data) { | ||
debug('Backup store was empty'); | ||
return Promise.reject(error); | ||
} | ||
debug('Metadata loaded from backupStore', data.length); | ||
return data; | ||
}) | ||
.catch((err) => { | ||
debug('Backup store request error', err); | ||
return Promise.reject(error); | ||
}); | ||
}); | ||
} catch(err) { | ||
debug('Backup store request error', err); | ||
throw error; | ||
} | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20823
276
124
5
+ Addedaxios@^0.19.0
+ Addedaxios@0.19.2(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
- Removedsuperagent@^5.1.0
- Removedasynckit@0.4.0(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcookiejar@2.1.4(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddunder-proto@1.0.0(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedfast-safe-stringify@2.1.1(transitive)
- Removedform-data@3.0.2(transitive)
- Removedformidable@1.2.6(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.6(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmath-intrinsics@1.0.0(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@2.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedqs@6.13.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@7.6.3(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedsuperagent@5.3.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)