Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.

Commit

Permalink
fix: fix authorization flow
Browse files Browse the repository at this point in the history
  • Loading branch information
spotify-kai committed Mar 11, 2021
1 parent 01f5882 commit 7959f3c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/imgur.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ imgur._imgurRequest = async (operation, payload, extraFormParams) => {
}

response = await imgur._request(options);
if (response && !response.success) {
const { statusCode: status, statusMessage: message } = response;
if (status !== 200) {
throw new Error({
status: response.status,
message: response.data ? response.error : 'No body data response',
status,
message,
});
} else {
return response.data;
return JSON.parse(response.body).data;
}
};

Expand All @@ -127,7 +128,7 @@ imgur._imgurRequest = async (operation, payload, extraFormParams) => {
* @param {object} options
* @returns {promise}
*/
imgur._request = async (options) => await got(options).json();
imgur._request = async (options) => await got(options);

/**
* Get imgur access token using credentials
Expand All @@ -144,7 +145,7 @@ imgur._getAuthorizationHeader = async () => {
}

const options = {
uri: 'https://api.imgur.com/oauth2/authorize',
url: 'https://api.imgur.com/oauth2/authorize',
method: 'GET',
encoding: 'utf8',
searchParams: {
Expand All @@ -166,8 +167,9 @@ imgur._getAuthorizationHeader = async () => {
password: imgurPassword,
allow: authorize_token,
};
options.followRedirect = false;
options.headers = {
Cookie: 'authorize_token=' + authorize_token,
cookie: 'authorize_token=' + authorize_token,
};

response = await imgur._request(options);
Expand Down

0 comments on commit 7959f3c

Please sign in to comment.