This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
|
||
namespace SourceLink | ||
{ | ||
public interface IAuthenticationHeaderValueProvider | ||
{ | ||
AuthenticationHeaderValue GetValue(); | ||
} | ||
|
||
internal class BasicAuthenticationHeaderValueProvider : IAuthenticationHeaderValueProvider | ||
{ | ||
private readonly string _username; | ||
private readonly string _password; | ||
private readonly Encoding _encoding; | ||
|
||
public BasicAuthenticationHeaderValueProvider(string username, string password, Encoding encoding = null) | ||
{ | ||
if (string.IsNullOrWhiteSpace(username)) throw new ArgumentNullException(nameof(username),"Invalid username value"); | ||
if (string.IsNullOrWhiteSpace(password)) throw new ArgumentNullException(nameof(password),"Invalid password value"); | ||
|
||
_username = username; | ||
_password = password; | ||
_encoding = encoding ?? Encoding.ASCII; | ||
} | ||
|
||
public AuthenticationHeaderValue GetValue() | ||
{ | ||
return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(_encoding.GetBytes($"{_username}:{_password}"))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters