csharp.libraries.generichost.ApiKeyToken.mustache Maven / Gradle / Ivy
//
{{partial_header}}
{{#nrt}}
#nullable enable
{{/nrt}}
using System;
namespace {{packageName}}.{{clientPackage}}
{
///
/// A token constructed from an apiKey.
///
{{>visibility}} class ApiKeyToken : TokenBase
{
private string _raw;
///
/// The header that this token will be used with.
///
public ClientUtils.ApiKeyHeader Header { get; }
///
/// Constructs an ApiKeyToken object.
///
///
///
///
///
public ApiKeyToken(string value, ClientUtils.ApiKeyHeader header, string prefix = "Bearer ", TimeSpan? timeout = null) : base(timeout)
{
Header = header;
_raw = $"{ prefix }{ value }";
}
///
/// Places the token in the header.
///
///
public virtual void UseInHeader(System.Net.Http.HttpRequestMessage request)
{
request.Headers.Add(ClientUtils.ApiKeyHeaderToString(Header), _raw);
}
///
/// Places the token in the query.
///
///
///
///
public virtual void UseInQuery(System.Net.Http.HttpRequestMessage request, UriBuilder uriBuilder, System.Collections.Specialized.NameValueCollection parseQueryString)
{
parseQueryString[ClientUtils.ApiKeyHeaderToString(Header)] = Uri.EscapeDataString(_raw).ToString(){{nrt!}};
}
}
}