csharp.libraries.generichost.BasicToken.mustache Maven / Gradle / Ivy
//
{{partial_header}}
{{#nrt}}
#nullable enable
{{/nrt}}
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace {{packageName}}.{{clientPackage}}
{
///
/// A token constructed from a username and password.
///
{{>visibility}} class BasicToken : TokenBase
{
private string _username;
private string _password;
///
/// Constructs a BasicToken object.
///
///
///
///
public BasicToken(string username, string password, TimeSpan? timeout = null) : base(timeout)
{
_username = username;
_password = password;
}
///
/// Places the token in the header.
///
///
///
public virtual void UseInHeader(System.Net.Http.HttpRequestMessage request, string headerName)
{
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", {{packageName}}.Client.ClientUtils.Base64Encode(_username + ":" + _password));
}
}
}