diff --git a/packages/rocketchat-custom-oauth/custom_oauth_server.js b/packages/rocketchat-custom-oauth/custom_oauth_server.js index 8a331d95051..1bed5e1b9a8 100644 --- a/packages/rocketchat-custom-oauth/custom_oauth_server.js +++ b/packages/rocketchat-custom-oauth/custom_oauth_server.js @@ -98,10 +98,17 @@ export class CustomOAuth { throw _.extend(error, {response: err.response}); } - if (response.data.error) { //if the http response was a json object with an error attribute - throw new Error(`Failed to complete OAuth handshake with ${ this.name } at ${ this.tokenPath }. ${ response.data.error }`); + let data; + if(response.data){ + data = response.data; } else { - return response.data.access_token; + data = JSON.parse(response.content); + } + + if (data.error) { //if the http response was a json object with an error attribute + throw new Error(`Failed to complete OAuth handshake with ${this.name} at ${this.tokenPath}. ${data.error}`); + } else { + return data.access_token; } }