Exemplo n.º 1
0
 public static bool CheckAuthorization(PeerCastStation.HTTP.HTTPRequest request, PeerCastStation.Core.AuthenticationKey key)
 {
     if (key == null)
     {
         return(true);
     }
     if (!request.Headers.ContainsKey("AUTHORIZATION"))
     {
         return(false);
     }
     else
     {
         var authorized = false;
         var md         = System.Text.RegularExpressions.Regex.Match(
             request.Headers["AUTHORIZATION"],
             @"\s*BASIC (\S+)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
         if (md.Success)
         {
             try {
                 var authorization = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(md.Groups[1].Value)).Split(':');
                 if (authorization.Length >= 2)
                 {
                     var user = authorization[0];
                     var pass = String.Join(":", authorization.Skip(1).ToArray());
                     if (key.Id == user && key.Password == pass)
                     {
                         authorized = true;
                     }
                 }
             }
             catch (FormatException) {
             }
             catch (ArgumentException) {
             }
         }
         return(authorized);
     }
 }
Exemplo n.º 2
0
        private static string GetAuthorizationToken(PeerCastStation.HTTP.HTTPRequest request)
        {
            String result = null;

            if (request.Headers.ContainsKey("AUTHORIZATION"))
            {
                var md = System.Text.RegularExpressions.Regex.Match(
                    request.Headers["AUTHORIZATION"],
                    @"\s*BASIC (\S+)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                if (md.Success)
                {
                    result = md.Groups[1].Value;
                }
            }
            if (result == null)
            {
                request.Parameters.TryGetValue("auth", out result);
            }
            if (result == null)
            {
                request.Cookies.TryGetValue("auth", out result);
            }
            return(result);
        }
Exemplo n.º 3
0
 public static bool CheckAuthorization(PeerCastStation.HTTP.HTTPRequest request, PeerCastStation.Core.AccessControlInfo acinfo)
 {
     return(CheckAuthorization(GetAuthorizationToken(request), acinfo));
 }