mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Merge 75f96c8814 into dab442f45b
This commit is contained in:
commit
81acaf7518
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)];
|
||||
|
|
|
|||
Loading…
Reference in a new issue