Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
get createToken() to work with axois
  • Loading branch information
benflap committed Nov 23, 2023
commit d720400334fed07a447d4111435c1b41645fc028
4 changes: 2 additions & 2 deletions src/OAuthClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ OAuthClient.prototype.createToken = function createToken(uri) {
resolve(this.getTokenRequest(request));
})
.then((res) => {
const authResponse = res.json ? res : null;
const json = (authResponse && authResponse.getJson()) || res;
const { response, ...authResponse } = res.json ? res : null;
const json = (authResponse && authResponse.json) || res;
this.token.setToken(json);
this.log('info', 'Create Token response is : ', JSON.stringify(authResponse, null, 2));
return authResponse;
Expand Down
16 changes: 5 additions & 11 deletions src/response/AuthResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function AuthResponse(params) {
*/
AuthResponse.prototype.processResponse = function processResponse(response) {
this.response = response || '';
this.body = (response && response.body) || '';
this.json = this.body && this.isJson() ? JSON.parse(this.body) : null;
this.body = (response && response.data) || '';
this.json = this.body && this.isJson() ? this.body : null;
this.intuit_tid = (response && response.headers && response.headers.intuit_tid) || '';
};

Expand All @@ -58,7 +58,6 @@ AuthResponse.prototype.getToken = function getToken() {
return this.token.getToken();
};


/**
* Get Token
* *
Expand Down Expand Up @@ -92,11 +91,9 @@ AuthResponse.prototype.headers = function headers() {
* @returns {*|boolean}
*/
AuthResponse.prototype.valid = function valid() {
return (this.response && Number(this.response.status) >= 200
&& Number(this.response.status) < 300);
return this.response && Number(this.response.status) >= 200 && Number(this.response.status) < 300;
};


/**
* Get Json () { returns token as JSON }
* *
Expand All @@ -119,7 +116,6 @@ AuthResponse.prototype.get_intuit_tid = function get_intuit_tid() {
return this.intuit_tid;
};


/**
* isContentType
* *
Expand All @@ -135,7 +131,7 @@ AuthResponse.prototype.isContentType = function isContentType(contentType) {
* @returns {string} getContentType
*/
AuthResponse.prototype.getContentType = function getContentType() {
return this.response.get(AuthResponse._contentType) || '';
return this.response.headers[AuthResponse._contentType] || '';
};

/**
Expand All @@ -147,10 +143,8 @@ AuthResponse.prototype.isJson = function isJson() {
return this.isContentType('application/json');
};


AuthResponse._contentType = 'Content-Type';
AuthResponse._contentType = 'content-type';
AuthResponse._jsonContentType = 'application/json';
AuthResponse._urlencodedContentType = 'application/x-www-form-urlencoded';


module.exports = AuthResponse;