All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csharp.libraries.generichost.BasicToken.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
// 
{{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));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy