fix: enhance TOTP handling and improve documentation for TOTPKey
This commit is contained in:
@@ -386,13 +386,24 @@ class RequestHandler {
|
|||||||
return this.execute(request, captcha, data.captcha_rqtoken);
|
return this.execute(request, captcha, data.captcha_rqtoken);
|
||||||
}
|
}
|
||||||
// Two factor handling
|
// Two factor handling
|
||||||
|
if (data?.code && data.code == 60003 && request.options.auth !== false && request.retries < 1) {
|
||||||
|
// https://gist.github.com/Dziurwa14/de2498e5ee28d2089f095aa037957cbb
|
||||||
|
// 60003: Two factor is required for this operation
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* message: "Two factor is required for this operation";
|
||||||
|
* code: 60003;
|
||||||
|
* mfa: {
|
||||||
|
* ticket: string;
|
||||||
|
* methods: {
|
||||||
|
* type: "password" | "totp" | "sms" | "backup" | "webauthn";
|
||||||
|
* }[];
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
*/
|
||||||
if (
|
if (
|
||||||
data?.code &&
|
data.mfa.methods.find(o => o.type === 'totp') &&
|
||||||
data.code == 60003 && // Two factor is required for this operation
|
typeof this.manager.client.options.TOTPKey === 'string'
|
||||||
data.mfa.methods.find(o => o.type === 'totp') && // TOTP is available
|
|
||||||
typeof this.manager.client.options.TOTPKey === 'string' &&
|
|
||||||
request.options.auth !== false &&
|
|
||||||
request.retries < 1
|
|
||||||
) {
|
) {
|
||||||
// Get mfa code
|
// Get mfa code
|
||||||
const otp = this.manager.client.authenticator.generate(this.manager.client.options.TOTPKey);
|
const otp = this.manager.client.authenticator.generate(this.manager.client.options.TOTPKey);
|
||||||
@@ -417,6 +428,7 @@ class RequestHandler {
|
|||||||
request.retries++;
|
request.retries++;
|
||||||
return this.execute(request);
|
return this.execute(request);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new HTTPError(err.message, err.constructor.name, err.status, request);
|
throw new HTTPError(err.message, err.constructor.name, err.status, request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ const Intents = require('./Intents');
|
|||||||
* @property {number} [DMChannelVoiceStatusSync=0] The amount of time in milliseconds that the Client to register the event with each DM channel (0=Disable)
|
* @property {number} [DMChannelVoiceStatusSync=0] The amount of time in milliseconds that the Client to register the event with each DM channel (0=Disable)
|
||||||
* @property {number} [captchaRetryLimit=3] Captcha retry limit
|
* @property {number} [captchaRetryLimit=3] Captcha retry limit
|
||||||
* @property {CaptchaSolver} [captchaSolver] Captcha Solver
|
* @property {CaptchaSolver} [captchaSolver] Captcha Solver
|
||||||
* @property {string} [TOTPKey] TOTP key for two-factor authentication
|
* @property {string} [TOTPKey] TOTP key / 2FA Key for two-factor authentication
|
||||||
|
* This is a 32-character Base32 string (excluding spaces), typically shown only once during your 2FA setup (QR code), or in the "Manual Entry" section.
|
||||||
|
* The library automatically removes spaces and converts the secret to uppercase.
|
||||||
|
* Example value: 'ftc3 uz6q 5lpw 2kew 4thr vtyp n2cu topn' or 'WSLIVE6EKYSRMVRBZLFGG2KVIVJMMQY5'
|
||||||
* @property {number} [closeTimeout=5000] The amount of time in milliseconds to wait for the close frame to be received
|
* @property {number} [closeTimeout=5000] The amount of time in milliseconds to wait for the close frame to be received
|
||||||
* from the WebSocket.
|
* from the WebSocket.
|
||||||
* <info>Don't have this too high/low. It's best to have it between 2000-6000 ms.</info>
|
* <info>Don't have this too high/low. It's best to have it between 2000-6000 ms.</info>
|
||||||
|
|||||||
Reference in New Issue
Block a user