This commit is contained in:
wildtylus 2021-12-06 00:39:18 +07:00 committed by GitHub
commit 81acaf7518
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 0 deletions

View file

@ -207,6 +207,21 @@ namespace TLSharp.Core
return request.Response.PhoneCodeHash;
}
public async Task<string> ResendCodeRequestAsync(string phoneNumber, string phoneCodeHash, CancellationToken token = default(CancellationToken))
{
if (String.IsNullOrWhiteSpace(phoneNumber))
throw new ArgumentNullException(nameof(phoneNumber));
if(String.IsNullOrWhiteSpace(phoneCodeHash))
throw new ArgumentNullException(nameof(phoneCodeHash));
var request = new TLRequestResendCode() { PhoneNumber = phoneNumber, PhoneCodeHash = phoneCodeHash };
await RequestWithDcMigration(request, token).ConfigureAwait(false);
return request.Response.PhoneCodeHash;
}
public async Task<TLUser> MakeAuthAsync(string phoneNumber, string phoneCodeHash, string code, CancellationToken token = default(CancellationToken))
{
if (String.IsNullOrWhiteSpace(phoneNumber))

View file

@ -21,6 +21,12 @@ namespace TLSharp.Tests
await base.AuthUser();
}
[Test]
public async override Task AuthUserByResendCode()
{
await base.AuthUserByResendCode();
}
[Test]
public override async Task SendMessageTest()
{

View file

@ -20,6 +20,12 @@ namespace TLSharp.Tests
await base.AuthUser();
}
[TestMethod]
public override async Task AuthUserByResendCode()
{
await base.AuthUserByResendCode();
}
[TestMethod]
public override async Task SendMessageTest()
{

View file

@ -155,6 +155,44 @@ namespace TLSharp.Tests
Assert.IsTrue(client.IsUserAuthorized());
}
public virtual async Task AuthUserByResendCode()
{
var client = NewClient();
await client.ConnectAsync();
var hash = await client.SendCodeRequestAsync(NumberToAuthenticate);
var resendHash = await client.ResendCodeRequestAsync(NumberToAuthenticate, hash);
var code = CodeToAuthenticate; // you can change code in debugger too
if (String.IsNullOrWhiteSpace(code))
{
throw new Exception("CodeToAuthenticate is empty in the app.config file, fill it with the code you just got now by SMS/Telegram");
}
TLUser user = null;
try
{
user = await client.MakeAuthAsync(NumberToAuthenticate, resendHash, code);
}
catch (CloudPasswordNeededException ex)
{
var passwordSetting = await client.GetPasswordSetting();
var password = PasswordToAuthenticate;
user = await client.MakeAuthWithPasswordAsync(passwordSetting, password);
}
catch (InvalidPhoneCodeException ex)
{
throw new Exception("CodeToAuthenticate is wrong in the app.config file, fill it with the code you just got now by SMS/Telegram",
ex);
}
Assert.IsNotNull(user);
Assert.IsTrue(client.IsUserAuthorized());
}
public virtual async Task SendMessageTest()
{
NumberToSendMessage = ConfigurationManager.AppSettings[nameof(NumberToSendMessage)];