client-oauth2
Advanced tools
Comparing version 3.0.2 to 3.1.0
{ | ||
"name": "client-oauth2", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Straight-forward execution of OAuth 2.0 flows and authenticated API requests", | ||
@@ -5,0 +5,0 @@ "main": "src/client-oauth2.js", |
@@ -110,26 +110,13 @@ var extend = require('xtend') | ||
*/ | ||
function getAuthError (data) { | ||
var message = ERROR_RESPONSES[data.error] || | ||
data.error || | ||
data.error_message | ||
function getAuthError (body) { | ||
var message = ERROR_RESPONSES[body.error] || | ||
body.error_description || | ||
body.error | ||
// Return an error instance with the message if it exists. | ||
return message && new Error(message) | ||
} | ||
/** | ||
* Handle the authentication response object. | ||
* | ||
* @param {Object} data | ||
* @return {Promise} | ||
*/ | ||
function handleAuthResponse (data) { | ||
var err = getAuthError(data) | ||
// If the response contains an error, reject the refresh token. | ||
if (err) { | ||
return Promise.reject(err) | ||
if (message) { | ||
var err = new Error(message) | ||
err.body = body | ||
err.code = 'EAUTH' | ||
return err | ||
} | ||
return Promise.resolve(data) | ||
} | ||
@@ -281,9 +268,18 @@ | ||
.then(function (res) { | ||
var body = parseResponseBody(res.body) | ||
var authErr = getAuthError(body) | ||
if (authErr) { | ||
return Promise.reject(authErr) | ||
} | ||
if (res.status < 200 || res.status >= 399) { | ||
var err = new Error('HTTP status ' + res.status) | ||
err.status = res.status | ||
err.body = parseResponseBody(res.body) | ||
return Promise.reject(err) | ||
var statusErr = new Error('HTTP status ' + res.status) | ||
statusErr.status = res.status | ||
statusErr.body = res.body | ||
statusErr.code = 'ESTATUS' | ||
return Promise.reject(statusErr) | ||
} | ||
return parseResponseBody(res.body) | ||
return body | ||
}) | ||
@@ -383,3 +379,2 @@ } | ||
}, options)) | ||
.then(handleAuthResponse) | ||
.then(function (data) { | ||
@@ -439,3 +434,2 @@ return self.client.createToken(extend(self.data, data)) | ||
}, options)) | ||
.then(handleAuthResponse) | ||
.then(function (data) { | ||
@@ -555,3 +549,2 @@ return self.client.createToken(data) | ||
}, options)) | ||
.then(handleAuthResponse) | ||
.then(function (data) { | ||
@@ -643,3 +636,2 @@ return self.client.createToken(data) | ||
}, options)) | ||
.then(handleAuthResponse) | ||
.then(function (data) { | ||
@@ -695,3 +687,2 @@ return self.client.createToken(data) | ||
}, options)) | ||
.then(handleAuthResponse) | ||
.then(function (data) { | ||
@@ -698,0 +689,0 @@ return self.client.createToken(data) |
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
28930
650