Skip to content
Open
Changes from all commits
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
7 changes: 5 additions & 2 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const getClientSecret = options => {

const getAuthorizationToken = async (code, options) => {
if (!options.clientID) throw new Error('clientID is empty');
if (!options.redirectUri) throw new Error('redirectUri is empty');
if (!options.clientSecret) throw new Error('clientSecret is empty');

const url = new URL(ENDPOINT_URL);
Expand All @@ -65,9 +64,13 @@ const getAuthorizationToken = async (code, options) => {
client_secret: options.clientSecret,
code,
grant_type: 'authorization_code',
redirect_uri: options.redirectUri,
};

// Passing redirect_uri is required when login happens through the browser.
if (options.redirectUri) {
form.redirect_uri = options.redirectUri;
}

const body = await request({ url: url.toString(), method: 'POST', form });
return JSON.parse(body);
};
Expand Down