Browse Source

fix: Trim token before passing it to the authorization header (#1578)

* Trim token

* Trim when assigning to AuthToken
tags/2.3.0
Paulo GitHub 4 years ago
parent
commit
42ba3720e3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 11 deletions
  1. +7
    -11
      src/Discord.Net.Rest/DiscordRestApiClient.cs

+ 7
- 11
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -80,17 +80,13 @@ namespace Discord.API
/// <exception cref="ArgumentException">Unknown OAuth token type.</exception>
internal static string GetPrefixedToken(TokenType tokenType, string token)
{
switch (tokenType)
return tokenType switch
{
case default(TokenType):
return token;
case TokenType.Bot:
return $"Bot {token}";
case TokenType.Bearer:
return $"Bearer {token}";
default:
throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType));
}
default(TokenType) => token,
TokenType.Bot => $"Bot {token}",
TokenType.Bearer => $"Bearer {token}",
_ => throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType)),
};
}
internal virtual void Dispose(bool disposing)
{
@@ -133,7 +129,7 @@ namespace Discord.API
RestClient.SetCancelToken(_loginCancelToken.Token);

AuthTokenType = tokenType;
AuthToken = token;
AuthToken = token?.TrimEnd();
if (tokenType != TokenType.Webhook)
RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken));



Loading…
Cancel
Save