Skip to content

Commit 89804b8

Browse files
author
Jonathon Hill
committed
fix: state-specific arguments did not work as documented
Resolves #21 , #23
1 parent e0fcec5 commit 89804b8

18 files changed

+2366
-2826
lines changed

dist/index.cjs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22

33
const qs = require('qs');
44

5-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
6-
7-
const qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
8-
95
function oauth(axios, { url, ...credentials }) {
10-
return (moreCredentials = {}) => axios({
11-
url,
12-
method: "post",
13-
data: qs__default.stringify({
6+
return (moreCredentials = {}) => {
7+
const body = {
148
...credentials,
159
...moreCredentials
16-
})
17-
}).then((res) => res.data);
10+
};
11+
if ("scope" in body && !body.scope) {
12+
delete body.scope;
13+
}
14+
return axios({
15+
url,
16+
method: "post",
17+
data: qs.stringify(body)
18+
}).then((res) => res.data);
19+
};
1820
}
19-
oauth.authorizationCode = function(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
20-
return oauth(axios, {
21+
22+
function authorizationCode(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
23+
const grant = oauth(axios, {
2124
url,
2225
grant_type: "authorization_code",
2326
client_id,
@@ -26,36 +29,50 @@ oauth.authorizationCode = function(axios, url, client_id, client_secret, redirec
2629
code,
2730
scope
2831
});
29-
};
30-
oauth.ownerCredentials = function(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
31-
return oauth(axios, {
32+
return (code2 = null, scope2 = null) => grant({ code: code2, scope: scope2 });
33+
}
34+
35+
function clientCredentials(axios, url, client_id, client_secret, scope = null) {
36+
const grant = oauth(axios, {
3237
url,
33-
grant_type: "password",
38+
grant_type: "client_credentials",
3439
client_id,
3540
client_secret,
36-
username,
37-
password,
3841
scope
3942
});
40-
};
41-
oauth.clientCredentials = function(axios, url, client_id, client_secret, scope = null) {
42-
return oauth(axios, {
43+
return (scope2) => grant(scope2 ? { scope: scope2 } : null);
44+
}
45+
46+
function ownerCredentials(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
47+
const grant = oauth(axios, {
4348
url,
44-
grant_type: "client_credentials",
49+
grant_type: "password",
4550
client_id,
4651
client_secret,
52+
username,
53+
password,
4754
scope
4855
});
49-
};
50-
oauth.refreshToken = function(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
51-
return oauth(axios, {
56+
return (username2 = null, password2 = null, scope2 = null) => grant({ username: username2, password: password2, scope: scope2 });
57+
}
58+
59+
function refreshToken(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
60+
const grant = oauth(axios, {
5261
url,
5362
grant_type: "refresh_token",
5463
client_id,
5564
client_secret,
5665
refresh_token,
5766
scope
5867
});
68+
return (refresh_token2 = null, scope2 = null) => grant({ refresh_token: refresh_token2, scope: scope2 });
69+
}
70+
71+
const index = {
72+
authorizationCode,
73+
clientCredentials,
74+
ownerCredentials,
75+
refreshToken
5976
};
6077

61-
module.exports = oauth;
78+
module.exports = index;

dist/index.d.ts

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import qs from 'qs';
22

33
function oauth(axios, { url, ...credentials }) {
4-
return (moreCredentials = {}) => axios({
5-
url,
6-
method: "post",
7-
data: qs.stringify({
4+
return (moreCredentials = {}) => {
5+
const body = {
86
...credentials,
97
...moreCredentials
10-
})
11-
}).then((res) => res.data);
8+
};
9+
if ("scope" in body && !body.scope) {
10+
delete body.scope;
11+
}
12+
return axios({
13+
url,
14+
method: "post",
15+
data: qs.stringify(body)
16+
}).then((res) => res.data);
17+
};
1218
}
13-
oauth.authorizationCode = function(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
14-
return oauth(axios, {
19+
20+
function authorizationCode(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
21+
const grant = oauth(axios, {
1522
url,
1623
grant_type: "authorization_code",
1724
client_id,
@@ -20,36 +27,50 @@ oauth.authorizationCode = function(axios, url, client_id, client_secret, redirec
2027
code,
2128
scope
2229
});
23-
};
24-
oauth.ownerCredentials = function(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
25-
return oauth(axios, {
30+
return (code2 = null, scope2 = null) => grant({ code: code2, scope: scope2 });
31+
}
32+
33+
function clientCredentials(axios, url, client_id, client_secret, scope = null) {
34+
const grant = oauth(axios, {
2635
url,
27-
grant_type: "password",
36+
grant_type: "client_credentials",
2837
client_id,
2938
client_secret,
30-
username,
31-
password,
3239
scope
3340
});
34-
};
35-
oauth.clientCredentials = function(axios, url, client_id, client_secret, scope = null) {
36-
return oauth(axios, {
41+
return (scope2) => grant(scope2 ? { scope: scope2 } : null);
42+
}
43+
44+
function ownerCredentials(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
45+
const grant = oauth(axios, {
3746
url,
38-
grant_type: "client_credentials",
47+
grant_type: "password",
3948
client_id,
4049
client_secret,
50+
username,
51+
password,
4152
scope
4253
});
43-
};
44-
oauth.refreshToken = function(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
45-
return oauth(axios, {
54+
return (username2 = null, password2 = null, scope2 = null) => grant({ username: username2, password: password2, scope: scope2 });
55+
}
56+
57+
function refreshToken(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
58+
const grant = oauth(axios, {
4659
url,
4760
grant_type: "refresh_token",
4861
client_id,
4962
client_secret,
5063
refresh_token,
5164
scope
5265
});
66+
return (refresh_token2 = null, scope2 = null) => grant({ refresh_token: refresh_token2, scope: scope2 });
67+
}
68+
69+
var index = {
70+
authorizationCode,
71+
clientCredentials,
72+
ownerCredentials,
73+
refreshToken
5374
};
5475

55-
export { oauth as default };
76+
export { index as default };

dist/index.mjs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import qs from 'qs';
22

33
function oauth(axios, { url, ...credentials }) {
4-
return (moreCredentials = {}) => axios({
5-
url,
6-
method: "post",
7-
data: qs.stringify({
4+
return (moreCredentials = {}) => {
5+
const body = {
86
...credentials,
97
...moreCredentials
10-
})
11-
}).then((res) => res.data);
8+
};
9+
if ("scope" in body && !body.scope) {
10+
delete body.scope;
11+
}
12+
return axios({
13+
url,
14+
method: "post",
15+
data: qs.stringify(body)
16+
}).then((res) => res.data);
17+
};
1218
}
13-
oauth.authorizationCode = function(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
14-
return oauth(axios, {
19+
20+
function authorizationCode(axios, url, client_id, client_secret, redirect_uri, code = null, scope = null) {
21+
const grant = oauth(axios, {
1522
url,
1623
grant_type: "authorization_code",
1724
client_id,
@@ -20,36 +27,50 @@ oauth.authorizationCode = function(axios, url, client_id, client_secret, redirec
2027
code,
2128
scope
2229
});
23-
};
24-
oauth.ownerCredentials = function(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
25-
return oauth(axios, {
30+
return (code2 = null, scope2 = null) => grant({ code: code2, scope: scope2 });
31+
}
32+
33+
function clientCredentials(axios, url, client_id, client_secret, scope = null) {
34+
const grant = oauth(axios, {
2635
url,
27-
grant_type: "password",
36+
grant_type: "client_credentials",
2837
client_id,
2938
client_secret,
30-
username,
31-
password,
3239
scope
3340
});
34-
};
35-
oauth.clientCredentials = function(axios, url, client_id, client_secret, scope = null) {
36-
return oauth(axios, {
41+
return (scope2) => grant(scope2 ? { scope: scope2 } : null);
42+
}
43+
44+
function ownerCredentials(axios, url, client_id, client_secret, username = null, password = null, scope = null) {
45+
const grant = oauth(axios, {
3746
url,
38-
grant_type: "client_credentials",
47+
grant_type: "password",
3948
client_id,
4049
client_secret,
50+
username,
51+
password,
4152
scope
4253
});
43-
};
44-
oauth.refreshToken = function(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
45-
return oauth(axios, {
54+
return (username2 = null, password2 = null, scope2 = null) => grant({ username: username2, password: password2, scope: scope2 });
55+
}
56+
57+
function refreshToken(axios, url, client_id, client_secret, refresh_token = null, scope = null) {
58+
const grant = oauth(axios, {
4659
url,
4760
grant_type: "refresh_token",
4861
client_id,
4962
client_secret,
5063
refresh_token,
5164
scope
5265
});
66+
return (refresh_token2 = null, scope2 = null) => grant({ refresh_token: refresh_token2, scope: scope2 });
67+
}
68+
69+
const index = {
70+
authorizationCode,
71+
clientCredentials,
72+
ownerCredentials,
73+
refreshToken
5374
};
5475

55-
export { oauth as default };
76+
export { index as default };

0 commit comments

Comments
 (0)