internal IPrincipal ParseBasicAuthentication(string authData) { try { // Basic AUTH Data is a formatted Base64 String //string domain = null; var authString = Encoding.UTF8.GetString(Convert.FromBase64String(authData)); // The format is DOMAIN\username:password // Domain is optional var pos = authString.IndexOf(':'); // parse the password off the end var password = authString.Substring(pos + 1); // discard the password authString = authString.Substring(0, pos); // check if there is a domain pos = authString.IndexOf('\\'); var user = pos > 0 ? authString.Substring(pos) : authString; var identity = new HttpListenerBasicIdentity(user, password); // TODO: What are the roles MS sets return(new GenericPrincipal(identity, new string[0])); } catch (Exception) { // Invalid auth data is swallowed silently return(null); } }
internal IPrincipal ParseBasicAuthentication(string authData) { try { // Basic AUTH Data is a formatted Base64 String //string domain = null; var authString = Encoding.GetEncoding(0).GetString(Convert.FromBase64String(authData)); // The format is DOMAIN\username:password // Domain is optional var pos = authString.IndexOf(':'); // parse the password off the end var password = authString.Substring(pos + 1); // discard the password authString = authString.Substring(0, pos); // check if there is a domain pos = authString.IndexOf('\\'); var user = pos > 0 ? authString.Substring(pos) : authString; var identity = new HttpListenerBasicIdentity(user, password); // TODO: What are the roles MS sets return new GenericPrincipal(identity, new string[0]); } catch (Exception) { // Invalid auth data is swallowed silently return null; } }