-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.cjs
72 lines (66 loc) · 1.89 KB
/
index.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
function oauth(axios, { url, ...credentials }) {
return (moreCredentials = {}) => {
const body = {
...credentials,
...moreCredentials
};
if ("scope" in body && !body.scope) {
delete body.scope;
}
return axios({
url,
method: "post",
data: new URLSearchParams(body).toString()
}).then((res) => res.data);
};
}
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,
client_secret,
redirect_uri,
code,
scope
});
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: "client_credentials",
client_id,
client_secret,
scope
});
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: "password",
client_id,
client_secret,
username,
password,
scope
});
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 });
}
exports.authorizationCode = authorizationCode;
exports.clientCredentials = clientCredentials;
exports.ownerCredentials = ownerCredentials;
exports.refreshToken = refreshToken;