client-oauth2
Advanced tools
Comparing version 3.0.0 to 3.0.1
{ | ||
"name": "client-oauth2", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Straight-forward execution of OAuth 2.0 flows and authenticated API requests", | ||
@@ -62,4 +62,5 @@ "main": "src/client-oauth2.js", | ||
"dependencies": { | ||
"popsicle": "^8.2.0", | ||
"xtend": "^4.0.1" | ||
} | ||
} |
@@ -33,3 +33,3 @@ # Client OAuth 2.0 | ||
**P.S.** The second argument to the constructor can inject a custom request function, and the third argument can inject a custom `Promise` implementation. | ||
**P.S.** The second argument to the constructor can inject a custom request function. | ||
@@ -89,3 +89,3 @@ ### Options (global and method-based) | ||
app.get('/auth/github/callback', function (req, res) { | ||
githubAuth.code.getToken(req.url) | ||
githubAuth.code.getToken(req.originalUrl) | ||
.then(function (user) { | ||
@@ -92,0 +92,0 @@ console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... } |
@@ -211,5 +211,4 @@ var extend = require('xtend') | ||
*/ | ||
function ClientOAuth2 (options, request, Promise) { | ||
function ClientOAuth2 (options, request) { | ||
this.options = options | ||
this.Promise = Promise || global.Promise | ||
this.request = request || defaultRequest | ||
@@ -222,6 +221,2 @@ | ||
this.jwt = new JwtBearerFlow(this) | ||
if (typeof this.Promise !== 'function') { | ||
throw new TypeError('A `Promise` implementation is required for `ClientOAuth2` to work') | ||
} | ||
} | ||
@@ -272,3 +267,3 @@ | ||
return this.request(options.method, url, body, options.headers, this.Promise) | ||
return this.request(options.method, url, body, options.headers) | ||
.then(function (res) { | ||
@@ -275,0 +270,0 @@ if (res.status < 200 || res.status >= 399) { |
@@ -8,6 +8,5 @@ /** | ||
* @param {Object} headers | ||
* @param {Promise} Promise | ||
* @returns {Promise} | ||
*/ | ||
module.exports = function request (method, url, body, headers, Promise) { | ||
module.exports = function request (method, url, body, headers) { | ||
return new Promise(function (resolve, reject) { | ||
@@ -14,0 +13,0 @@ var xhr = new window.XMLHttpRequest() |
@@ -1,8 +0,5 @@ | ||
var http = require('http') | ||
var https = require('https') | ||
var Url = require('url') | ||
var createUnzip = require('zlib').createUnzip | ||
var popsicle = require('popsicle') | ||
/** | ||
* Make a request using node HTTP(s). | ||
* Make a request using node. | ||
* | ||
@@ -13,45 +10,16 @@ * @param {String} method | ||
* @param {Object} headers | ||
* @param {Promise} Promise | ||
* @returns {Promise} | ||
*/ | ||
module.exports = function request (method, url, body, headers, Promise) { | ||
return new Promise(function (resolve, reject) { | ||
var requestOptions = Url.parse(url) | ||
var lib = requestOptions.protocol === 'https:' ? https : http | ||
requestOptions.method = method | ||
requestOptions.headers = headers | ||
// Send the http request and listen for the response to finish. | ||
var request = lib.request(requestOptions, function (res) { | ||
var data = '' | ||
var stream = res | ||
var encoding = res.headers['content-encoding'] | ||
if (encoding === 'deflate' || encoding === 'gzip') { | ||
var unzip = createUnzip() | ||
unzip.on('error', reject) | ||
stream.pipe(unzip) | ||
stream = unzip | ||
} | ||
stream.on('error', reject) | ||
stream.on('data', function (chunk) { | ||
data += chunk | ||
}) | ||
stream.on('end', function () { | ||
return resolve({ | ||
status: res.statusCode, | ||
body: data | ||
}) | ||
}) | ||
}) | ||
request.on('error', reject) | ||
request.write(body) | ||
request.end() | ||
module.exports = function request (method, url, body, headers) { | ||
return popsicle.get({ | ||
url: url, | ||
body: body, | ||
method: method, | ||
headers: headers | ||
}).then(function (res) { | ||
return { | ||
status: res.status, | ||
body: res.body | ||
} | ||
}) | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
0
29254
2
652
+ Addedpopsicle@^8.2.0
+ Addedany-promise@1.3.0(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@2.5.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmake-error@1.3.6(transitive)
+ Addedmake-error-cause@1.2.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedpopsicle@8.2.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrowback@1.1.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)