public static UserDataPrincipal InitFromHeaders(HttpRequestHeaders headers) { var authHeader = headers.Authorization; var tfsUrl = headers.GetTfsUrl(); if (authHeader == null || !authHeader.Scheme.Equals("basic", StringComparison.OrdinalIgnoreCase) || String.IsNullOrWhiteSpace(tfsUrl)) { return null; } string userName = null; string password = null; string decodedAuthHeader = Encoding.Default.GetString(Convert.FromBase64String(authHeader.Parameter)); var usernamePasswordTokens = decodedAuthHeader.Split(new[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries); if (usernamePasswordTokens.Length >= 2) { userName = usernamePasswordTokens[0]; password = usernamePasswordTokens[1]; } if (String.IsNullOrWhiteSpace(tfsUrl) || String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(password)) return null; var principal = new UserDataPrincipal(tfsUrl, userName, password); return principal; }