Fix can not get access_token when using custom oauth

pull/6531/head
fhalcyon 9 years ago
parent 112f2e6187
commit 1f466c24fe
  1. 13
      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;
}
}

Loading…
Cancel
Save