@ -82,12 +82,12 @@ namespace Discord.API
{
switch ( tokenType )
{
case default ( TokenType ) :
return token ;
case TokenType . Bot :
return $"Bot {token}" ;
case TokenType . Bearer :
return $"Bearer {token}" ;
case TokenType . User :
return token ;
default :
throw new ArgumentException ( message : "Unknown OAuth token type." , paramName : nameof ( tokenType ) ) ;
}
@ -127,7 +127,7 @@ namespace Discord.API
{
_loginCancelToken ? . Dispose ( ) ;
_loginCancelToken = new CancellationTokenSource ( ) ;
AuthTokenType = TokenType . User ;
AuthToken = null ;
await RequestQueue . SetCancelTokenAsync ( _loginCancelToken . Token ) . ConfigureAwait ( false ) ;
RestClient . SetCancelToken ( _loginCancelToken . Token ) ;
@ -186,7 +186,7 @@ namespace Discord.API
{
options = options ? ? new RequestOptions ( ) ;
options . HeaderOnly = true ;
options . BucketId = bucketId;
options . BucketId = AuthTokenType = = TokenType . User ? ClientBucket . Get ( clientBucket ) . Id : bucketId;
var request = new RestRequest ( RestClient , method , endpoint , options ) ;
await SendInternalAsync ( method , endpoint , request ) . ConfigureAwait ( false ) ;
@ -200,7 +200,7 @@ namespace Discord.API
{
options = options ? ? new RequestOptions ( ) ;
options . HeaderOnly = true ;
options . BucketId = bucketId;
options . BucketId = AuthTokenType = = TokenType . User ? ClientBucket . Get ( clientBucket ) . Id : bucketId;
string json = payload ! = null ? SerializeJson ( payload ) : null ;
var request = new JsonRestRequest ( RestClient , method , endpoint , json , options ) ;
@ -215,7 +215,7 @@ namespace Discord.API
{
options = options ? ? new RequestOptions ( ) ;
options . HeaderOnly = true ;
options . BucketId = bucketId;
options . BucketId = AuthTokenType = = TokenType . User ? ClientBucket . Get ( clientBucket ) . Id : bucketId;
var request = new MultipartRestRequest ( RestClient , method , endpoint , multipartArgs , options ) ;
await SendInternalAsync ( method , endpoint , request ) . ConfigureAwait ( false ) ;
@ -228,7 +228,7 @@ namespace Discord.API
string bucketId = null , ClientBucketType clientBucket = ClientBucketType . Unbucketed , RequestOptions options = null ) where TResponse : class
{
options = options ? ? new RequestOptions ( ) ;
options . BucketId = bucketId;
options . BucketId = AuthTokenType = = TokenType . User ? ClientBucket . Get ( clientBucket ) . Id : bucketId;
var request = new RestRequest ( RestClient , method , endpoint , options ) ;
return DeserializeJson < TResponse > ( await SendInternalAsync ( method , endpoint , request ) . ConfigureAwait ( false ) ) ;
@ -241,7 +241,7 @@ namespace Discord.API
string bucketId = null , ClientBucketType clientBucket = ClientBucketType . Unbucketed , RequestOptions options = null ) where TResponse : class
{
options = options ? ? new RequestOptions ( ) ;
options . BucketId = bucketId;
options . BucketId = AuthTokenType = = TokenType . User ? ClientBucket . Get ( clientBucket ) . Id : bucketId;
string json = payload ! = null ? SerializeJson ( payload ) : null ;
var request = new JsonRestRequest ( RestClient , method , endpoint , json , options ) ;
@ -255,7 +255,8 @@ namespace Discord.API
string bucketId = null , ClientBucketType clientBucket = ClientBucketType . Unbucketed , RequestOptions options = null )
{
options = options ? ? new RequestOptions ( ) ;
options . BucketId = bucketId ;
options . BucketId = AuthTokenType = = TokenType . User ? ClientBucket . Get ( clientBucket ) . Id : bucketId ;
var request = new MultipartRestRequest ( RestClient , method , endpoint , multipartArgs , options ) ;
return DeserializeJson < TResponse > ( await SendInternalAsync ( method , endpoint , request ) . ConfigureAwait ( false ) ) ;