fix: Trim token before passing it to the authorization header (#1578)
* Trim token * Trim when assigning to AuthToken
This commit is contained in:
@@ -80,17 +80,13 @@ namespace Discord.API
|
|||||||
/// <exception cref="ArgumentException">Unknown OAuth token type.</exception>
|
/// <exception cref="ArgumentException">Unknown OAuth token type.</exception>
|
||||||
internal static string GetPrefixedToken(TokenType tokenType, string token)
|
internal static string GetPrefixedToken(TokenType tokenType, string token)
|
||||||
{
|
{
|
||||||
switch (tokenType)
|
return tokenType switch
|
||||||
{
|
{
|
||||||
case default(TokenType):
|
default(TokenType) => token,
|
||||||
return token;
|
TokenType.Bot => $"Bot {token}",
|
||||||
case TokenType.Bot:
|
TokenType.Bearer => $"Bearer {token}",
|
||||||
return $"Bot {token}";
|
_ => throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType)),
|
||||||
case TokenType.Bearer:
|
};
|
||||||
return $"Bearer {token}";
|
|
||||||
default:
|
|
||||||
throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
internal virtual void Dispose(bool disposing)
|
internal virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
@@ -133,7 +129,7 @@ namespace Discord.API
|
|||||||
RestClient.SetCancelToken(_loginCancelToken.Token);
|
RestClient.SetCancelToken(_loginCancelToken.Token);
|
||||||
|
|
||||||
AuthTokenType = tokenType;
|
AuthTokenType = tokenType;
|
||||||
AuthToken = token;
|
AuthToken = token?.TrimEnd();
|
||||||
if (tokenType != TokenType.Webhook)
|
if (tokenType != TokenType.Webhook)
|
||||||
RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken));
|
RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user