fetch-mw-oauth2
Advanced tools
Comparing version 0.7.6 to 0.7.7
Changelog | ||
========= | ||
0.7.7 (2021-02-22) | ||
------------------ | ||
* Last version did not correctly build it's files. | ||
0.7.6 (2021-02-22) | ||
@@ -5,0 +11,0 @@ ------------------ |
@@ -86,3 +86,5 @@ "use strict"; | ||
}; | ||
let usesBasicAuth = false; | ||
if (options.clientSecret !== undefined) { | ||
usesBasicAuth = true; | ||
const basicAuthStr = base64_1.encode(options.clientId + ':' + options.clientSecret); | ||
@@ -103,7 +105,20 @@ headers.Authorization = 'Basic ' + basicAuthStr; | ||
} | ||
let errorMessage = 'OAuth2 error ' + jsonResult.error + '.'; | ||
if (jsonResult.error_description) { | ||
errorMessage += ' ' + jsonResult.error_description; | ||
const httpError = authResult.status; | ||
let errorMessage; | ||
let oauth2Code; | ||
if (jsonResult.error) { | ||
errorMessage = 'OAuth2 error ' + jsonResult.error + '.'; | ||
if (jsonResult.error_description) { | ||
errorMessage += ' ' + jsonResult.error_description; | ||
} | ||
oauth2Code = jsonResult.error; | ||
} | ||
throw new error_1.default(errorMessage, jsonResult.error, 401); | ||
else { | ||
errorMessage = 'HTTP Error ' + authResult.status + ' ' + authResult.statusText; | ||
if (authResult.status === 401 && usesBasicAuth) { | ||
errorMessage += '. It\'s likely that the clientId and/or clientSecret was incorrect'; | ||
} | ||
oauth2Code = null; | ||
} | ||
throw new error_1.default(errorMessage, oauth2Code, httpError); | ||
} | ||
@@ -110,0 +125,0 @@ const newToken = { |
{ | ||
"name": "fetch-mw-oauth2", | ||
"version": "0.7.6", | ||
"version": "0.7.7", | ||
"description": "Fetch middleware to add OAuth2 support", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
74162
1119