public static async Task <bool> AuthorizeAsync(HttpContext context, IDashboardHandle handle, DashboardRoute route) { if (context.Request.Headers.ContainsKey(BasicConfig.AuthToken)) { return(true); } if (handle.GetType().GetMethod(route.Action).GetCustomAttribute <AllowAnonymousAttribute>() != null) { return(await Task.FromResult(true)); } if (context.Request.Path.HasValue) { if (!BasicConfig.CurrentControllers.IsEmpty()) { if (!BasicConfig.CurrentControllers.Split(',').Select(x => x.ToLowerInvariant()).Contains(route.Handle.ToLowerInvariant())) { return(await Task.FromResult(true)); } } } string username = context.Request.Cookies[BasicConfig.LoginCookieId]; if (string.IsNullOrEmpty(username)) { context.Response.Redirect("/HttpReports/UserLogin"); return(await Task.FromResult(false)); } return(await Task.FromResult(true)); }
public bool ValidToken(HttpContext httpContext, IDashboardHandle handle, DashboardRoute route) { if (httpContext == null) { return(false); } if (handle.GetType().GetMethod(route.Action).GetCustomAttribute <AllowAnonymousAttribute>() != null) { return(true); } if (httpContext.Request.Path.HasValue) { if (!BasicConfig.CurrentControllers.IsEmpty()) { if (!BasicConfig.CurrentControllers.Split(',').Select(x => x.ToLowerInvariant()).Contains(route.Handle.ToLowerInvariant())) { return(true); } } } StringValues token; if (!httpContext.Request.Headers.TryGetValue(BasicConfig.AuthToken, out token)) { return(false); } return(ValidToken(token.ToString())); }