public static Hashtable RequestKey(string Description) { System.Collections.Hashtable ht = new System.Collections.Hashtable(); HttpContext context = HttpContext.Current; if (context.User.Identity.IsAuthenticated) { try { vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager(); vwar.service.host.APIKey key = keyMan.CreateKey(context.User.Identity.Name, context.Server.HtmlEncode(Description)); ht["Key"] = key.Key; ht["Usage"] = key.Usage; ht["Active"] = (key.State == vwar.service.host.APIKeyState.ACTIVE) ? "Yes" : "No"; ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyRequestSuccess"]; } catch { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyRequestError"]; } } else { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyRequestError"]; } return(ht); }
public static string DeleteKey(string Key) { string msg = ""; HttpContext context = HttpContext.Current; if (context.User.Identity.IsAuthenticated) { try { vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager(); if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name)) { keyMan.DeleteKey(Key); msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteSuccess"]; } else { msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"]; } } catch { msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"]; } } else { context.Response.StatusCode = 401; } return(msg); }
public static Hashtable RequestKey(string Description) { System.Collections.Hashtable ht = new System.Collections.Hashtable(); HttpContext context = HttpContext.Current; if (context.User.Identity.IsAuthenticated) { try { vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager(); vwar.service.host.APIKey key = keyMan.CreateKey(context.User.Identity.Name, context.Server.HtmlEncode(Description)); ht["Key"] = key.Key; ht["Usage"] = key.Usage; ht["Active"] = (key.State == vwar.service.host.APIKeyState.ACTIVE) ? "Yes" : "No"; ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyRequestSuccess"]; } catch { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyRequestError"]; } } else { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyRequestError"]; } return ht; }
public static string DeleteKey(string Key) { string msg = ""; HttpContext context = HttpContext.Current; if (context.User.Identity.IsAuthenticated) { try { vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager(); if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name)) { keyMan.DeleteKey(Key); msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteSuccess"]; } else { msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"]; } } catch { msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"]; } } else { context.Response.StatusCode = 401; } return msg; }
public override void SetupTest() { base.SetupTest(); Login(false); mTestKey = new APIKey(); mTestKey.Email = ConfigurationManager.AppSettings["_3DR_UserName"]; mTestKey.Usage = "This is a test for the key request"; mKeyMananger = new APIKeyManager(); }
public void SetupTest() { _baseUrl = ConfigurationManager.AppSettings["ServiceUrl"]; _apiKey = new APIKeyManager() .CreateKey(ConfigurationManager.AppSettings["_3DR_UserName"], ConfigurationManager.AppSettings["_3DR_Password"]).Key; _serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); }
public static Hashtable UpdateKey(string Key, string Description) { System.Collections.Hashtable ht = new System.Collections.Hashtable(); HttpContext context = HttpContext.Current; if (context.User.Identity.IsAuthenticated) { try { vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager(); if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name)) { vwar.service.host.APIKey currentKey = keyMan.GetKeyByKey(Key); currentKey.Usage = context.Server.HtmlEncode(Description); if (keyMan.UpdateKey(currentKey)) { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateSuccess"]; ht["Usage"] = currentKey.Usage; } else { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"]; } } else { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"]; } } catch { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"]; } } else { context.Response.StatusCode = 401; } return(ht); }
public static Hashtable UpdateKey(string Key, string Description) { System.Collections.Hashtable ht = new System.Collections.Hashtable(); HttpContext context = HttpContext.Current; if (context.User.Identity.IsAuthenticated) { try { vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager(); if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name)) { vwar.service.host.APIKey currentKey = keyMan.GetKeyByKey(Key); currentKey.Usage = context.Server.HtmlEncode(Description); if (keyMan.UpdateKey(currentKey)) { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateSuccess"]; ht["Usage"] = currentKey.Usage; } else { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"]; } } else { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"]; } } catch { ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"]; } } else { context.Response.StatusCode = 401; } return ht; }
public virtual bool CheckKey(string key) { APIKeyManager KeyManager = new APIKeyManager(); if (key == null) { WebOperationContext.Current.OutgoingResponse.Headers[System.Net.HttpResponseHeader.WwwAuthenticate] = "BASIC realm=\"3DR API\""; WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Unauthorized; // throw new WebFaultException(System.Net.HttpStatusCode.Unauthorized); return false; } if (KeyManager.GetUserByKey(key) == null) { WebOperationContext.Current.OutgoingResponse.Headers[System.Net.HttpResponseHeader.WwwAuthenticate] = "BASIC realm=\"3DR API\""; WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Unauthorized; // throw new WebFaultException(System.Net.HttpStatusCode.Unauthorized); return false; } KeyManager.Dispose(); return true; }