mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Support the request to resend the verification_code through alternate methods.
This commit is contained in:
parent
62dad83370
commit
97c6de4cbb
2
.github/dev.yml
vendored
2
.github/dev.yml
vendored
|
|
@ -2,7 +2,7 @@ pr: none
|
||||||
trigger:
|
trigger:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
name: 1.7.7-dev.$(Rev:r)
|
name: 1.8.1-dev.$(Rev:r)
|
||||||
|
|
||||||
pool:
|
pool:
|
||||||
vmImage: ubuntu-latest
|
vmImage: ubuntu-latest
|
||||||
|
|
|
||||||
2
.github/release.yml
vendored
2
.github/release.yml
vendored
|
|
@ -1,7 +1,7 @@
|
||||||
pr: none
|
pr: none
|
||||||
trigger: none
|
trigger: none
|
||||||
|
|
||||||
name: 1.7.$(Rev:r)
|
name: 1.8.$(Rev:r)
|
||||||
|
|
||||||
pool:
|
pool:
|
||||||
vmImage: ubuntu-latest
|
vmImage: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ using var client = new WTelegram.Client(Config);
|
||||||
There are other configuration items that are queried to your method but returning `null` let WTelegramClient choose a default adequate value.
|
There are other configuration items that are queried to your method but returning `null` let WTelegramClient choose a default adequate value.
|
||||||
Those shown above are the only ones that have no default values and should be provided by your method.
|
Those shown above are the only ones that have no default values and should be provided by your method.
|
||||||
Returning `null` for verification_code or password will show a prompt for console apps, or an error otherwise.
|
Returning `null` for verification_code or password will show a prompt for console apps, or an error otherwise.
|
||||||
|
Returning an empty string for verification_code requests resending the code through another method (SMS or Call).
|
||||||
|
|
||||||
Another simple approach is to pass `Environment.GetEnvironmentVariable` as the config callback and define the configuration items as environment variables.
|
Another simple approach is to pass `Environment.GetEnvironmentVariable` as the config callback and define the configuration items as environment variables.
|
||||||
Undefined variables get the default `null` behavior.
|
Undefined variables get the default `null` behavior.
|
||||||
|
|
|
||||||
|
|
@ -1020,13 +1020,26 @@ namespace WTelegram
|
||||||
{
|
{
|
||||||
sentCode = await this.Auth_SendCode(phone_number, _apiId, _apiHash, settings ??= new());
|
sentCode = await this.Auth_SendCode(phone_number, _apiId, _apiHash, settings ??= new());
|
||||||
}
|
}
|
||||||
|
resent:
|
||||||
|
var timeout = DateTime.UtcNow + TimeSpan.FromSeconds(sentCode.timeout);
|
||||||
|
OnUpdate(sentCode);
|
||||||
Helpers.Log(3, $"A verification code has been sent via {sentCode.type.GetType().Name[17..]}");
|
Helpers.Log(3, $"A verification code has been sent via {sentCode.type.GetType().Name[17..]}");
|
||||||
Auth_AuthorizationBase authorization = null;
|
Auth_AuthorizationBase authorization = null;
|
||||||
//TODO: implement auth.resendCode logic
|
|
||||||
for (int retry = 1; authorization == null; retry++)
|
for (int retry = 1; authorization == null; retry++)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var verification_code = await ConfigAsync("verification_code");
|
var verification_code = await ConfigAsync("verification_code");
|
||||||
|
if (verification_code == "" && sentCode.next_type != 0)
|
||||||
|
{
|
||||||
|
var mustWait = timeout - DateTime.UtcNow;
|
||||||
|
if (mustWait.Ticks > 0)
|
||||||
|
{
|
||||||
|
Helpers.Log(3, $"You must wait {(int)(mustWait.TotalSeconds + 0.5)} more seconds before requesting the code to be sent via {sentCode.next_type}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sentCode = await this.Auth_ResendCode(phone_number, sentCode.phone_code_hash);
|
||||||
|
goto resent;
|
||||||
|
}
|
||||||
authorization = await this.Auth_SignIn(phone_number, sentCode.phone_code_hash, verification_code);
|
authorization = await this.Auth_SignIn(phone_number, sentCode.phone_code_hash, verification_code);
|
||||||
}
|
}
|
||||||
catch (RpcException e) when (e.Code == 401 && e.Message == "SESSION_PASSWORD_NEEDED")
|
catch (RpcException e) when (e.Code == 401 && e.Message == "SESSION_PASSWORD_NEEDED")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue