mirror of https://github.com/Xhofe/alist
feat(mega): add 2FA support (#6473)
* feat(mega): add support for two-factor authentication in Mega driver #6226 * feat(mega): remove debug print statement in Mega driver Init function * feat(mega): add help message for new fieldpull/6500/head
parent
037850bbd5
commit
9eec872637
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/pkg/http_range"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"github.com/rclone/rclone/lib/readers"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
|
@ -33,8 +34,16 @@ func (d *Mega) GetAddition() driver.Additional {
|
|||
}
|
||||
|
||||
func (d *Mega) Init(ctx context.Context) error {
|
||||
var twoFACode = d.TwoFACode
|
||||
d.c = mega.New()
|
||||
return d.c.Login(d.Email, d.Password)
|
||||
if d.TwoFASecret != "" {
|
||||
code, err := totp.GenerateCode(d.TwoFASecret, time.Now())
|
||||
if err != nil {
|
||||
return fmt.Errorf("generate totp code failed: %w", err)
|
||||
}
|
||||
twoFACode = code
|
||||
}
|
||||
return d.c.MultiFactorLogin(d.Email, d.Password, twoFACode)
|
||||
}
|
||||
|
||||
func (d *Mega) Drop(ctx context.Context) error {
|
||||
|
|
|
@ -11,6 +11,8 @@ type Addition struct {
|
|||
//driver.RootID
|
||||
Email string `json:"email" required:"true"`
|
||||
Password string `json:"password" required:"true"`
|
||||
TwoFACode string `json:"two_fa_code" required:"false" help:"2FA 6-digit code, filling in the 2FA code alone will not support reloading driver"`
|
||||
TwoFASecret string `json:"two_fa_secret" required:"false" help:"2FA secret"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
|
|
Loading…
Reference in New Issue