Skip to content

Commit

Permalink
fix: state-specific arguments did not work as documented
Browse files Browse the repository at this point in the history
Resolves #21 , #23
  • Loading branch information
Jonathon Hill committed Dec 7, 2022
1 parent e0fcec5 commit 89804b8
Show file tree
Hide file tree
Showing 18 changed files with 2,366 additions and 2,826 deletions.
69 changes: 43 additions & 26 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

const qs = require('qs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }

const qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);

function oauth(axios, { url, ...credentials }) {
return (moreCredentials = {}) => axios({
url,
method: "post",
data: qs__default.stringify({
return (moreCredentials = {}) => {
const body = {
...credentials,
...moreCredentials
})
}).then((res) => res.data);
};
if ("scope" in body && !body.scope) {
delete body.scope;
}
return axios({
url,
method: "post",
data: qs.stringify(body)
}).then((res) => res.data);
};
}
oauth.authorizationCode = function(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
return oauth(axios, {

function authorizationCode(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "authorization_code",
client_id,
Expand All @@ -26,36 +29,50 @@ oauth.authorizationCode = function(axios, url, client_id, client_secret, redirec
code,
scope
});
};
oauth.ownerCredentials = function(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
return oauth(axios, {
return (code2 = null, scope2 = null) => grant({ code: code2, scope: scope2 });
}

function clientCredentials(axios, url, client_id, client_secret, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "password",
grant_type: "client_credentials",
client_id,
client_secret,
username,
password,
scope
});
};
oauth.clientCredentials = function(axios, url, client_id, client_secret, scope = null) {
return oauth(axios, {
return (scope2) => grant(scope2 ? { scope: scope2 } : null);
}

function ownerCredentials(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "client_credentials",
grant_type: "password",
client_id,
client_secret,
username,
password,
scope
});
};
oauth.refreshToken = function(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
return oauth(axios, {
return (username2 = null, password2 = null, scope2 = null) => grant({ username: username2, password: password2, scope: scope2 });
}

function refreshToken(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "refresh_token",
client_id,
client_secret,
refresh_token,
scope
});
return (refresh_token2 = null, scope2 = null) => grant({ refresh_token: refresh_token2, scope: scope2 });
}

const index = {
authorizationCode,
clientCredentials,
ownerCredentials,
refreshToken
};

module.exports = oauth;
module.exports = index;
65 changes: 43 additions & 22 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import qs from 'qs';

function oauth(axios, { url, ...credentials }) {
return (moreCredentials = {}) => axios({
url,
method: "post",
data: qs.stringify({
return (moreCredentials = {}) => {
const body = {
...credentials,
...moreCredentials
})
}).then((res) => res.data);
};
if ("scope" in body && !body.scope) {
delete body.scope;
}
return axios({
url,
method: "post",
data: qs.stringify(body)
}).then((res) => res.data);
};
}
oauth.authorizationCode = function(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
return oauth(axios, {

function authorizationCode(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "authorization_code",
client_id,
Expand All @@ -20,36 +27,50 @@ oauth.authorizationCode = function(axios, url, client_id, client_secret, redirec
code,
scope
});
};
oauth.ownerCredentials = function(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
return oauth(axios, {
return (code2 = null, scope2 = null) => grant({ code: code2, scope: scope2 });
}

function clientCredentials(axios, url, client_id, client_secret, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "password",
grant_type: "client_credentials",
client_id,
client_secret,
username,
password,
scope
});
};
oauth.clientCredentials = function(axios, url, client_id, client_secret, scope = null) {
return oauth(axios, {
return (scope2) => grant(scope2 ? { scope: scope2 } : null);
}

function ownerCredentials(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "client_credentials",
grant_type: "password",
client_id,
client_secret,
username,
password,
scope
});
};
oauth.refreshToken = function(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
return oauth(axios, {
return (username2 = null, password2 = null, scope2 = null) => grant({ username: username2, password: password2, scope: scope2 });
}

function refreshToken(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "refresh_token",
client_id,
client_secret,
refresh_token,
scope
});
return (refresh_token2 = null, scope2 = null) => grant({ refresh_token: refresh_token2, scope: scope2 });
}

var index = {
authorizationCode,
clientCredentials,
ownerCredentials,
refreshToken
};

export { oauth as default };
export { index as default };
65 changes: 43 additions & 22 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import qs from 'qs';

function oauth(axios, { url, ...credentials }) {
return (moreCredentials = {}) => axios({
url,
method: "post",
data: qs.stringify({
return (moreCredentials = {}) => {
const body = {
...credentials,
...moreCredentials
})
}).then((res) => res.data);
};
if ("scope" in body && !body.scope) {
delete body.scope;
}
return axios({
url,
method: "post",
data: qs.stringify(body)
}).then((res) => res.data);
};
}
oauth.authorizationCode = function(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
return oauth(axios, {

function authorizationCode(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "authorization_code",
client_id,
Expand All @@ -20,36 +27,50 @@ oauth.authorizationCode = function(axios, url, client_id, client_secret, redirec
code,
scope
});
};
oauth.ownerCredentials = function(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
return oauth(axios, {
return (code2 = null, scope2 = null) => grant({ code: code2, scope: scope2 });
}

function clientCredentials(axios, url, client_id, client_secret, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "password",
grant_type: "client_credentials",
client_id,
client_secret,
username,
password,
scope
});
};
oauth.clientCredentials = function(axios, url, client_id, client_secret, scope = null) {
return oauth(axios, {
return (scope2) => grant(scope2 ? { scope: scope2 } : null);
}

function ownerCredentials(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "client_credentials",
grant_type: "password",
client_id,
client_secret,
username,
password,
scope
});
};
oauth.refreshToken = function(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
return oauth(axios, {
return (username2 = null, password2 = null, scope2 = null) => grant({ username: username2, password: password2, scope: scope2 });
}

function refreshToken(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
const grant = oauth(axios, {
url,
grant_type: "refresh_token",
client_id,
client_secret,
refresh_token,
scope
});
return (refresh_token2 = null, scope2 = null) => grant({ refresh_token: refresh_token2, scope: scope2 });
}

const index = {
authorizationCode,
clientCredentials,
ownerCredentials,
refreshToken
};

export { oauth as default };
export { index as default };

0 comments on commit 89804b8

Please sign in to comment.