private StatelessAuthenticationConfiguration GetConfiguration() { return(new StatelessAuthenticationConfiguration(ctx => { var isJsonRequest = false; var apiKey = RequestHelper.GetApiKey(ctx); if (string.IsNullOrEmpty(apiKey)) { ctx.Response = new Response { StatusCode = HttpStatusCode.Unauthorized }; return null; } var apikeyDao = new ApiKeyDAOImpl(); var key = apikeyDao.FindByKey(apiKey); if (key != null) { if (!key.IsValidKey()) { key.Key = null; key.CreateTime = DateTime.MinValue; apikeyDao.Update(key); } else { return key; } } if (key is null && isJsonRequest) { ctx.Response = Response.AsJson(new { message = "Invalid Key" }, HttpStatusCode.BadRequest); return null; } ctx.Response = new RedirectResponse("user", RedirectResponse.RedirectType.SeeOther); return null; })); }
private StatelessAuthenticationConfiguration GetConfiguration() { return(new StatelessAuthenticationConfiguration(ctx => { var apiKey = RequestHelper.GetApiKey(ctx); if (string.IsNullOrEmpty(apiKey)) { return null; } var apikeyDao = new ApiKeyDAOImpl(); var key = apikeyDao.FindByKey(apiKey); if (key != null && key.IsValidKey()) { ctx.Response = new RedirectResponse("main", RedirectResponse.RedirectType.SeeOther); } return key; })); }