Browse Source

Fixed several issues with tokens cache

tags/docs-0.9
RogueException 9 years ago
parent
commit
2457fc2455
1 changed files with 13 additions and 12 deletions
  1. +13
    -12
      src/Discord.Net/DiscordClient.cs

+ 13
- 12
src/Discord.Net/DiscordClient.cs View File

@@ -226,25 +226,26 @@ namespace Discord
byte[] cacheKey = null;

//Get Token
if (token == null && Config.CacheToken)
if (email != null && Config.CacheToken)
{
Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(password,
new byte[] { 0x5A, 0x2A, 0xF8, 0xCF, 0x78, 0xD3, 0x7D, 0x0D });
cacheKey = deriveBytes.GetBytes(16);

tokenPath = GetTokenCachePath(email);
oldToken = LoadToken(tokenPath, cacheKey);
ClientAPI.Token = oldToken;
if (token == null && password != null)
{
Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(password,
new byte[] { 0x5A, 0x2A, 0xF8, 0xCF, 0x78, 0xD3, 0x7D, 0x0D });
cacheKey = deriveBytes.GetBytes(16);

oldToken = LoadToken(tokenPath, cacheKey);
token = oldToken;
}
}
else
ClientAPI.Token = token;

ClientAPI.Token = token;
var request = new LoginRequest() { Email = email, Password = password };
var response = await ClientAPI.Send(request).ConfigureAwait(false);
token = response.Token;
if (Config.CacheToken && token != oldToken)
if (Config.CacheToken && token != oldToken && tokenPath != null)
SaveToken(tokenPath, cacheKey, token);

ClientAPI.Token = token;

//Cache other stuff


Loading…
Cancel
Save