catto.js 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AuthClient.js +19 -10
- package/package.json +1 -1
package/AuthClient.js
CHANGED
|
@@ -42,18 +42,21 @@ module.exports = class {
|
|
|
42
42
|
try {
|
|
43
43
|
var result = await request.post({
|
|
44
44
|
"url": "https://discord.com/api/oauth2/token",
|
|
45
|
-
"
|
|
45
|
+
"headers": {
|
|
46
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
47
|
+
},
|
|
48
|
+
"body": new URLSearchParams({
|
|
46
49
|
"client_id": this.options.id,
|
|
47
50
|
"client_secret": this.options.secret,
|
|
48
51
|
"grant_type": "authorization_code",
|
|
49
52
|
"code": req.query.code,
|
|
50
53
|
"redirect_uri": this.redirectUri
|
|
51
|
-
}
|
|
54
|
+
})
|
|
52
55
|
});
|
|
53
56
|
} catch(e) {
|
|
54
57
|
return !1;
|
|
55
58
|
}
|
|
56
|
-
if (result.response.
|
|
59
|
+
if (result.response.status == 200) {
|
|
57
60
|
this.writeToken(result.body);
|
|
58
61
|
return !0;
|
|
59
62
|
} else {
|
|
@@ -67,17 +70,20 @@ module.exports = class {
|
|
|
67
70
|
try {
|
|
68
71
|
var result = await request.post({
|
|
69
72
|
"url": "https://discord.com/api/oauth2/token",
|
|
70
|
-
"
|
|
73
|
+
"headers": {
|
|
74
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
75
|
+
},
|
|
76
|
+
"body": new URLSearchParams({
|
|
71
77
|
"client_id": this.options.id,
|
|
72
78
|
"client_secret": this.options.secret,
|
|
73
79
|
"grant_type": "refresh_token",
|
|
74
80
|
"refreshToken": this.options.refreshToken
|
|
75
|
-
}
|
|
81
|
+
})
|
|
76
82
|
});
|
|
77
83
|
} catch(e) {
|
|
78
84
|
return !1;
|
|
79
85
|
}
|
|
80
|
-
if (result.response.
|
|
86
|
+
if (result.response.status == 200) {
|
|
81
87
|
this.writeToken(result.body);
|
|
82
88
|
return !0;
|
|
83
89
|
} else {
|
|
@@ -91,16 +97,19 @@ module.exports = class {
|
|
|
91
97
|
try {
|
|
92
98
|
var result = await request.post({
|
|
93
99
|
"url": "https://discord.com/api/oauth2/token/revoke",
|
|
94
|
-
"
|
|
100
|
+
"headers": {
|
|
101
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
102
|
+
},
|
|
103
|
+
"body": new URLSearchParams({
|
|
95
104
|
"client_id": this.options.id,
|
|
96
105
|
"client_secret": this.options.secret,
|
|
97
106
|
"token": this.options.accessToken
|
|
98
|
-
}
|
|
107
|
+
})
|
|
99
108
|
});
|
|
100
109
|
} catch(e) {
|
|
101
110
|
return !1;
|
|
102
111
|
}
|
|
103
|
-
if (result.response.
|
|
112
|
+
if (result.response.status == 200) {
|
|
104
113
|
this.options.accessToken = "";
|
|
105
114
|
this.options.refreshToken = "";
|
|
106
115
|
return !0;
|
|
@@ -122,7 +131,7 @@ module.exports = class {
|
|
|
122
131
|
} catch(e) {
|
|
123
132
|
return !1;
|
|
124
133
|
}
|
|
125
|
-
if (result.response.
|
|
134
|
+
if (result.response.status == 200) {
|
|
126
135
|
this.user = new User(result.body);
|
|
127
136
|
return !0;
|
|
128
137
|
} else {
|