SHARE
TWEET

Mashape secret code verification (upd)

priore Jan 25th, 2013 183 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // updated: 03-04-2013
  2. //
  3.  
  4. using System.Web;
  5.  
  6. public static class Mashape // www.mashape.com/priore
  7.     {
  8.         private static string[] VALID_MASHAPE_ADDR = new string[] { "23.21.64.131", "23.21.68.63", "23.23.86.71", "23.23.87.232", "23.23.103.203", "23.23.103.204", "23.23.103.207", "23.23.103.212", "23.23.103.218", "50.17.255.165" };
  9.  
  10.         public static bool IsValidSecretCode(string secret_code)
  11.         {
  12.             HttpContext context = HttpContext.Current;
  13.             if (context == null)
  14.                 throw new ArgumentException("Invalid HTTP Context!");
  15.             return IsValidSecretCode(secret_code, context);
  16.         }
  17.  
  18.         public static bool IsValidSecretCode(string secret_code, HttpContext context)
  19.         {
  20.             string keySecret = "HTTP_X_MASHAPE_PROXY_SECRET:" + secret_code;
  21.             string tagSubscr = "HTTP_X_MASHAPE_SUBSCRIPTION:";
  22.  
  23.             HttpRequest request = context.Request;
  24.             string remote_addr = request.ServerVariables["REMOTE_ADDR"];
  25.             string all_http = request.ServerVariables["ALL_HTTP"];
  26.             return VALID_MASHAPE_ADDR.Contains(remote_addr) && all_http.Contains(keySecret) && all_http.Contains(tagSubscr);
  27.         }
  28.     }
RAW Paste Data
Top