|
|
@@ -52,19 +52,14 @@ namespace Discord.Rest |
|
|
|
/// <inheritdoc /> |
|
|
|
public async Task LoginAsync(TokenType tokenType, string token, bool validateToken = true) |
|
|
|
{ |
|
|
|
// If token validation is enabled, validate the token and let it throw any ArgumentExceptions |
|
|
|
// that result from invalid parameters |
|
|
|
if (validateToken) |
|
|
|
TokenUtils.ValidateToken(tokenType, token); |
|
|
|
|
|
|
|
await _stateLock.WaitAsync().ConfigureAwait(false); |
|
|
|
try |
|
|
|
{ |
|
|
|
await LoginInternalAsync(tokenType, token).ConfigureAwait(false); |
|
|
|
await LoginInternalAsync(tokenType, token, validateToken).ConfigureAwait(false); |
|
|
|
} |
|
|
|
finally { _stateLock.Release(); } |
|
|
|
} |
|
|
|
private async Task LoginInternalAsync(TokenType tokenType, string token) |
|
|
|
private async Task LoginInternalAsync(TokenType tokenType, string token, bool validateToken) |
|
|
|
{ |
|
|
|
if (_isFirstLogin) |
|
|
|
{ |
|
|
@@ -78,6 +73,21 @@ namespace Discord.Rest |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
// If token validation is enabled, validate the token and let it throw any ArgumentExceptions |
|
|
|
// that result from invalid parameters |
|
|
|
if (validateToken) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
TokenUtils.ValidateToken(tokenType, token); |
|
|
|
} |
|
|
|
catch (ArgumentException ex) |
|
|
|
{ |
|
|
|
// log these ArgumentExceptions and allow for the client to attempt to log in anyways |
|
|
|
await LogManager.WarningAsync("Discord", "A supplied token was invalid", ex).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
await ApiClient.LoginAsync(tokenType, token).ConfigureAwait(false); |
|
|
|
await OnLoginAsync(tokenType, token).ConfigureAwait(false); |
|
|
|
LoginState = LoginState.LoggedIn; |
|
|
|