1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-08 16:36:15 +00:00

Auth work

This commit is contained in:
Jan Korf 2021-12-08 21:49:25 +01:00
parent c2105fe690
commit b7cd6a866a
4 changed files with 45 additions and 32 deletions

View File

@ -47,7 +47,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns>
public abstract void AuthenticateUriRequest(
RestApiClient apiClient,
ref Uri uri,
Uri uri,
HttpMethod method,
SortedDictionary<string, object> parameters,
Dictionary<string, string> headers,

View File

@ -300,7 +300,7 @@ namespace CryptoExchange.Net
if (apiClient.AuthenticationProvider != null)
{
if(parameterPosition == HttpMethodParameterPosition.InUri)
apiClient.AuthenticationProvider.AuthenticateUriRequest(apiClient, ref uri, method, sortedParameters, headers, signed, arraySerialization);
apiClient.AuthenticationProvider.AuthenticateUriRequest(apiClient, uri, method, sortedParameters, headers, signed, arraySerialization);
else
apiClient.AuthenticationProvider.AuthenticateBodyRequest(apiClient, uri, method, sortedParameters, headers, signed, arraySerialization);
}
@ -309,15 +309,7 @@ namespace CryptoExchange.Net
{
// Add the auth parameters to the uri, start with a new URI to be able to sort the parameters including the auth parameters
if (sortedParameters.Count != length)
{
var uriBuilder = new UriBuilder();
uriBuilder.Scheme = uri.Scheme;
uriBuilder.Host = uri.Host;
uriBuilder.Path = uri.AbsolutePath;
uri = uriBuilder.Uri;
foreach(var parameter in sortedParameters)
uri = uri.AddQueryParmeter(parameter.Key, parameter.Value.ToString());
}
uri = uri.SetParameters(sortedParameters);
}
var request = RequestFactory.Create(method, uri, requestId);

View File

@ -165,26 +165,6 @@ namespace CryptoExchange.Net
return formData.ToString();
}
/// <summary>
/// Add parameter to URI
/// </summary>
/// <param name="uri"></param>
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns></returns>
public static Uri AddQueryParmeter(this Uri uri, string name, string value)
{
var httpValueCollection = HttpUtility.ParseQueryString(uri.Query);
httpValueCollection.Remove(name);
httpValueCollection.Add(name, value);
var ub = new UriBuilder(uri);
ub.Query = httpValueCollection.ToString();
return ub.Uri;
}
/// <summary>
/// Get the string the secure string is representing
@ -433,6 +413,47 @@ namespace CryptoExchange.Net
}
return path;
}
/// <summary>
/// Create a new uri with the provided parameters as query
/// </summary>
/// <param name="parameters"></param>
/// <param name="baseUri"></param>
/// <returns></returns>
public static Uri SetParameters(this Uri baseUri, SortedDictionary<string, object> parameters)
{
var uriBuilder = new UriBuilder();
uriBuilder.Scheme = baseUri.Scheme;
uriBuilder.Host = baseUri.Host;
uriBuilder.Path = baseUri.AbsolutePath;
var httpValueCollection = HttpUtility.ParseQueryString(string.Empty);
foreach (var parameter in parameters)
httpValueCollection.Add(parameter.Key, parameter.Value.ToString());
uriBuilder.Query = httpValueCollection.ToString();
return uriBuilder.Uri;
}
/// <summary>
/// Add parameter to URI
/// </summary>
/// <param name="uri"></param>
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns></returns>
public static Uri AddQueryParmeter(this Uri uri, string name, string value)
{
var httpValueCollection = HttpUtility.ParseQueryString(uri.Query);
httpValueCollection.Remove(name);
httpValueCollection.Add(name, value);
var ub = new UriBuilder(uri);
ub.Query = httpValueCollection.ToString();
return ub.Uri;
}
}
}

View File

@ -278,7 +278,7 @@ namespace CryptoExchange.Net.Objects
/// <summary>
/// Whether or not to automatically sync the local time with the server time
/// </summary>
public bool AutoTimestamp { get; set; } = true;
public bool AutoTimestamp { get; set; }
/// <summary>
/// ctor