Created
October 10, 2018 12:24
-
-
Save odahcam/1ec47edce421fed2f294275310b6146e to your computer and use it in GitHub Desktop.
Method for creating a Basic Auth token for HTTP in C#.
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
using System; | |
using System.Text; | |
namespace MyNamespace | |
{ | |
public class MyClass | |
{ | |
/// <summary> | |
/// Creates an Authentication Token for "Basic Auth" HTTP Authorization. | |
/// </summary> | |
/// | |
/// <param name="username"></param> | |
/// <param name="password"></param> | |
/// | |
/// <returns></returns> | |
protected static string BasicAuthToken(string username, string password) | |
{ | |
var encoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{username}:{password}")); | |
return $"Basic {encoded}"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment