Added initial support for Mega MFA

This commit is contained in:
Salvatore Gabriele La Greca 2023-03-19 19:48:13 +01:00
parent 97276ce765
commit ac2f03c823

View File

@ -66,6 +66,10 @@ func init() {
Help: "Password.",
Required: true,
IsPassword: true,
}, {
Name: "mfac",
Help: "Multi-factor authentication code.",
Required: false,
}, {
Name: "debug",
Help: `Output more debug from Mega.
@ -109,6 +113,7 @@ Enabling it will increase CPU usage and add network overhead.`,
type Options struct {
User string `config:"user"`
Pass string `config:"pass"`
MFAC string `config:"mfac"`
Debug bool `config:"debug"`
HardDelete bool `config:"hard_delete"`
UseHTTPS bool `config:"use_https"`
@ -226,7 +231,14 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
})
}
err := srv.Login(opt.User, opt.Pass)
// Login to mega
if opt.MFAC != "" {
// Login with MFA if set in the config by the user
err = srv.MultiFactorLogin(opt.User, opt.Pass, opt.MFAC)
} else {
err = srv.Login(opt.User, opt.Pass)
}
if err != nil {
return nil, fmt.Errorf("couldn't login: %w", err)
}