Merge pull request #4571 from vfrz/feature/mega_two_fa_3696
Add support for mega.nz two factor authentication.
This commit is contained in:
@@ -31,12 +31,15 @@
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MegaApiClient, Version=1.7.1.495, Culture=neutral, PublicKeyToken=0480d311efbeb4e2, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\MegaApiClient.1.7.1\lib\net46\MegaApiClient.dll</HintPath>
|
||||
<Reference Include="MegaApiClient, Version=1.9.0.0, Culture=neutral, PublicKeyToken=0480d311efbeb4e2">
|
||||
<HintPath>..\..\..\..\packages\MegaApiClient.1.9.0\lib\net46\MegaApiClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Otp.NET, Version=1.2.2.0, Culture=neutral, PublicKeyToken=38a48df817e173a6">
|
||||
<HintPath>..\..\..\..\packages\Otp.NET.1.2.2\lib\net45\Otp.NET.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Web" />
|
||||
|
||||
@@ -22,6 +22,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OtpNet;
|
||||
|
||||
namespace Duplicati.Library.Backend.Mega
|
||||
{
|
||||
@@ -31,6 +32,7 @@ namespace Duplicati.Library.Backend.Mega
|
||||
{
|
||||
private readonly string m_username = null;
|
||||
private readonly string m_password = null;
|
||||
private readonly string m_twoFactorKey = null;
|
||||
private Dictionary<string, List<INode>> m_filecache;
|
||||
private INode m_currentFolder = null;
|
||||
private readonly string m_prefix = null;
|
||||
@@ -48,7 +50,13 @@ namespace Duplicati.Library.Backend.Mega
|
||||
if (m_client == null)
|
||||
{
|
||||
var cl = new MegaApiClient();
|
||||
cl.Login(m_username, m_password);
|
||||
if (m_twoFactorKey == null)
|
||||
cl.Login(m_username, m_password);
|
||||
else
|
||||
{
|
||||
var totp = new Totp(Base32Encoding.ToBytes(m_twoFactorKey)).ComputeTotp();
|
||||
cl.Login(m_username, m_password, totp);
|
||||
}
|
||||
m_client = cl;
|
||||
}
|
||||
|
||||
@@ -64,6 +72,8 @@ namespace Duplicati.Library.Backend.Mega
|
||||
m_username = options["auth-username"];
|
||||
if (options.ContainsKey("auth-password"))
|
||||
m_password = options["auth-password"];
|
||||
if (options.ContainsKey("auth-two-factor-key"))
|
||||
m_twoFactorKey = options["auth-two-factor-key"];
|
||||
|
||||
if (!string.IsNullOrEmpty(uri.Username))
|
||||
m_username = uri.Username;
|
||||
@@ -253,6 +263,7 @@ namespace Duplicati.Library.Backend.Mega
|
||||
return new List<ICommandLineArgument>(new ICommandLineArgument[] {
|
||||
new CommandLineArgument("auth-password", CommandLineArgument.ArgumentType.Password, Strings.MegaBackend.AuthPasswordDescriptionShort, Strings.MegaBackend.AuthPasswordDescriptionLong),
|
||||
new CommandLineArgument("auth-username", CommandLineArgument.ArgumentType.String, Strings.MegaBackend.AuthUsernameDescriptionShort, Strings.MegaBackend.AuthUsernameDescriptionLong),
|
||||
new CommandLineArgument("auth-two-factor-key", CommandLineArgument.ArgumentType.Password, Strings.MegaBackend.AuthTwoFactorKeyDescriptionShort, Strings.MegaBackend.AuthTwoFactorKeyDescriptionLong),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ namespace Duplicati.Library.Backend.Strings {
|
||||
public static string AuthPasswordDescriptionShort { get { return LC.L(@"Supplies the password used to connect to the server"); } }
|
||||
public static string AuthUsernameDescriptionLong { get { return LC.L(@"The username used to connect to the server. This may also be supplied as the environment variable ""AUTH_USERNAME""."); } }
|
||||
public static string AuthUsernameDescriptionShort { get { return LC.L(@"Supplies the username used to connect to the server"); } }
|
||||
public static string AuthTwoFactorKeyDescriptionShort { get { return LC.L(@"The shared secret used to generate two-factor TOTP codes."); } }
|
||||
public static string AuthTwoFactorKeyDescriptionLong { get { return LC.L(@"For accounts with two-factor authentication enabled, this is the shared secret used to generate the two-factor TOTP codes."); } }
|
||||
public static string NoPasswordError { get { return LC.L(@"No password given"); } }
|
||||
public static string NoUsernameError { get { return LC.L(@"No username given"); } }
|
||||
public static string Description { get { return LC.L(@"This backend can read and write data to Mega.co.nz. Allowed formats are: ""mega://folder/subfolder"""); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MegaApiClient" version="1.7.1" targetFramework="net471" />
|
||||
<package id="MegaApiClient" version="1.9.0" targetFramework="net471" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net471" />
|
||||
</packages>
|
||||
<package id="Otp.NET" version="1.2.2" targetFramework="net471" />
|
||||
</packages>
|
||||
@@ -70,6 +70,18 @@
|
||||
<Link>licenses\gpg\License.txt</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\thirdparty\Otp.NET\Homepage.txt">
|
||||
<Link>licenses\Otp.NET\Homepage.txt</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\thirdparty\Otp.NET\license.txt">
|
||||
<Link>licenses\Otp.NET\license.txt</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\thirdparty\Otp.NET\licensedata.json">
|
||||
<Link>licenses\Otp.NET\licensedata.json</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\thirdparty\SharpCompress\download.txt">
|
||||
<Link>licenses\SharpCompress\download.txt</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
https://github.com/kspearrin/Otp.NET
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Kyle Spearrin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "Otp.NET",
|
||||
"description": "An implementation TOTP RFC 6238 and HOTP RFC 4226 in C#.",
|
||||
"link": "https://github.com/kspearrin/Otp.NET",
|
||||
"license": "MIT",
|
||||
"notes": ""
|
||||
}
|
||||
Reference in New Issue
Block a user