@@ -7,6 +7,15 @@ namespace Discord
/// </summary>
/// </summary>
public static class TokenUtils
public static class TokenUtils
{
{
/// <summary>
/// The minimum length of a Bot token.
/// </summary>
/// <remarks>
/// This value was determined by comparing against the examples in the Discord
/// documentation, and pre-existing tokens.
/// </remarks>
internal const int MinBotTokenLength = 58;
/// <summary>
/// <summary>
/// Checks the validity of the supplied token of a specific type.
/// Checks the validity of the supplied token of a specific type.
/// </summary>
/// </summary>
@@ -29,11 +38,11 @@ namespace Discord
// no validation is performed on Bearer tokens
// no validation is performed on Bearer tokens
break;
break;
case TokenType.Bot:
case TokenType.Bot:
// bot tokens are assumed to be at least 59 characters in length
// bot tokens are assumed to be at least 58 characters in length
// this value was determined by referencing examples in the discord documentation, and by comparing with
// this value was determined by referencing examples in the discord documentation, and by comparing with
// pre-existing tokens
// pre-existing tokens
if (token.Length < 59 )
throw new ArgumentException(message: "A Bot token must be at least 59 characters in length.", paramName: nameof(token));
if (token.Length < MinBotTokenLength )
throw new ArgumentException(message: $"A Bot token must be at least {MinBotTokenLength} characters in length.", paramName: nameof(token));
break;
break;
default:
default:
// All unrecognized TokenTypes (including User tokens) are considered to be invalid.
// All unrecognized TokenTypes (including User tokens) are considered to be invalid.