
csharp-netcore.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;
///
/// Constructs an ApiKeyToken object.
///
///
///
///
public ApiKeyToken(string value, string prefix = "Bearer ", TimeSpan? timeout = null) : base(timeout)
{
_raw = $"{ prefix }{ value }";
}
///
/// Places the token in the header.
///
///
///
public virtual void UseInHeader(System.Net.Http.HttpRequestMessage request, string headerName)
{
request.Headers.Add(headerName, _raw);
}
///
/// Places the token in the query.
///
///
///
///
///
public virtual void UseInQuery(System.Net.Http.HttpRequestMessage request, UriBuilder uriBuilder, System.Collections.Specialized.NameValueCollection parseQueryString, string parameterName)
{
parseQueryString[parameterName] = Uri.EscapeDataString(_raw).ToString(){{nrt!}};
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy