public static ServiceInfo ParseRequest(HttpContext context) { try { var data = RequestDataParser.Parse(null, schemas, context); return(data.ToObject <ServiceInfo>()); } catch (Exception ex) { throw new Exception("Parse ServiceModel failed.", ex); } }
private async Task TokenRequest(HttpContext context, Func <Task> next) { if (!context.Request.Path.Equals(options.Path, StringComparison.Ordinal)) { await next(); } else if (!context.Request.Method.Equals("POST")) { context.Response.StatusCode = 400; await context.Response.WriteAsync("Bad request."); } else { context.Response.ContentType = "application/json"; try { var data = RequestDataParser.Parse(null, schemas, context); var authData = await AuthIndentifierManager.AuthIdentifier.GetAuthData(data.Value <string>("username"), data.Value <string>("password")); if (authData == null && authData.Identity == null) { context.Response.StatusCode = 400; await context.Response.WriteAsync("Invalid username or password."); return; } JObject token = FillToken(authData); await context.Response.WriteAsync(token.ToString(Formatting.Indented)); } catch (Exception ex) { await context.Response.WriteAsync($"Authorization failed. {Environment.NewLine}{ex.Message}"); } } }
public object Execute() { var data = RequestDataParser.Parse(null, CRIModel.Schemas, HttpContext); var model = data.ToObject <CRIItem>(); if (ConfigurationManager.Settings.CRI.ApiOnly) { throw new Exception("CRI is only allowed for API, or set 'ApiOnly' to false in config.json file."); } RedisContext redisContext = new RedisContext(); if (!methods.ContainsKey(model.method)) { throw new Exception($"The method '{model.method}' is not supproted."); } var method = methods[model.method]; var result = method.Invoke(redisContext, new object[] { model }); return(AjaxResult.SetResult(result)); }