public async Task <ActionResult> Login(LoginModel model) { if (!ModelState.IsValid) { return(View()); } var authProxy = new AuthenticationProxy(MvcApplication.GetApiUrl(), "/api/oauth"); var token = await authProxy.Login(model.UserName, model.Password); if (token == null) { ModelState.AddModelError("password", ErrorMessages.IncorrectLogin); return(View()); } var tokenCookie = new HttpCookie("token", token.Value) { Expires = DateTime.Now.AddSeconds(token.ExpiresIn), HttpOnly = false }; var roleCookie = new HttpCookie("role", token.Role) { Expires = DateTime.Now.AddSeconds(token.ExpiresIn), HttpOnly = true }; Response.Cookies.Add(tokenCookie); Response.Cookies.Add(roleCookie); return(RedirectToAction("Index", "Dashboard")); }
private async Task EnsureReportAccess(Report report) { var loginProxy = new AuthenticationProxy(MvcApplication.GetApiUrl(), "/api/oauth"); var token = await loginProxy.LoginAnonymous(report.AnonymousToken); // TODO: add error handling var authCookie = new HttpCookie("token", token.Value) { Expires = DateTime.Now.AddMinutes(token.ExpiresIn) }; var cookie = new HttpCookie("report", report.Id.ToString()); Response.Cookies.Add(cookie); Response.Cookies.Add(authCookie); }
protected override void OnActionExecuting(ActionExecutingContext context) { _reportProxy = new Proxy <Report>(MvcApplication.GetApiUrl() + "reports"); var tokenCookie = Request.Cookies["token"]; if (tokenCookie != null) { _reportProxy.Token = new Token { Value = tokenCookie.Value }; } base.OnActionExecuting(context); }
private void CreateReportProxy() { _reportProxy = new Proxy <Report>(MvcApplication.GetApiUrl() + "reports"); }