feat: mfa request
This commit is contained in:
parent
e8c2b967c3
commit
f8a9641d76
@ -106,6 +106,9 @@ class APIRequest {
|
||||
'base64',
|
||||
);
|
||||
}
|
||||
if (this.options.mfaToken) {
|
||||
headers['X-Discord-Mfa-Authorization'] = this.options.mfaToken;
|
||||
}
|
||||
|
||||
let body;
|
||||
if (this.options.files?.length) {
|
||||
|
@ -355,6 +355,7 @@ class RequestHandler {
|
||||
let data;
|
||||
try {
|
||||
data = await parseResponse(res);
|
||||
// Captcha
|
||||
if (
|
||||
data?.captcha_service &&
|
||||
typeof this.manager.client.options.captchaSolver == 'function' &&
|
||||
@ -384,6 +385,29 @@ class RequestHandler {
|
||||
request.retries++;
|
||||
return this.execute(request, captcha, data.captcha_rqtoken);
|
||||
}
|
||||
// Two factor
|
||||
if (data?.code && data.code == 60003 && request.options.mfaCode && request.retries < 1) {
|
||||
this.manager.client.emit(
|
||||
DEBUG,
|
||||
`${data.message}
|
||||
Method : ${request.method}
|
||||
Path : ${request.path}
|
||||
Route : ${request.route}
|
||||
mfaCode : ${request.options.mfaCode}`,
|
||||
);
|
||||
// Get ticket
|
||||
const mfaData = data.mfa;
|
||||
const mfaPost = await this.manager.client.api.mfa.finish.post({
|
||||
data: {
|
||||
ticket: mfaData.ticket,
|
||||
data: request.options.mfaCode,
|
||||
mfa_type: 'totp',
|
||||
},
|
||||
});
|
||||
request.options.mfaToken = mfaPost.token;
|
||||
request.retries++;
|
||||
return this.execute(request);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new HTTPError(err.message, err.constructor.name, err.status, request);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user