fix cookies on ws auth
This commit is contained in:
parent
a960c71e76
commit
69c95c27ac
@ -11,14 +11,13 @@ use persistent::Read;
|
||||
use router::Router;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
// use warden::{warden};
|
||||
// use events::{pg_listen};
|
||||
// use ws::{connect};
|
||||
use account;
|
||||
use pg::PgPool;
|
||||
use payments::{stripe};
|
||||
|
||||
pub const TOKEN_HEADER: &str = "x-auth-token";
|
||||
pub const AUTH_CLEAR: &str =
|
||||
"x-auth-token=; HttpOnly; SameSite=Strict; Max-Age=-1;";
|
||||
|
||||
#[derive(Clone, Copy, Fail, Debug, Serialize, Deserialize)]
|
||||
pub enum MnmlHttpError {
|
||||
@ -142,9 +141,6 @@ impl BeforeMiddleware for AuthMiddleware {
|
||||
}
|
||||
}
|
||||
|
||||
const AUTH_CLEAR: &str =
|
||||
"x-auth-token=; HttpOnly; SameSite=Strict; Max-Age=-1;";
|
||||
|
||||
struct ErrorHandler;
|
||||
impl AfterMiddleware for ErrorHandler {
|
||||
fn catch(&self, _: &mut Request, mut err: IronError) -> IronResult<Response> {
|
||||
|
||||
@ -26,7 +26,7 @@ use pg::{Db};
|
||||
use pg::{PgPool};
|
||||
use skill::{Skill, dev_resolve, Resolutions};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
||||
use net::TOKEN_HEADER;
|
||||
use net::{AUTH_CLEAR, TOKEN_HEADER};
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub enum RpcMessage {
|
||||
@ -289,7 +289,11 @@ impl Handler for Connection {
|
||||
let res = Response::from_request(req)?;
|
||||
|
||||
if let Some(cl) = req.header("Cookie") {
|
||||
let unauth = || Ok(Response::new(401, "Unauthorized", b"401 - Unauthorized".to_vec()));
|
||||
let unauth = || {
|
||||
let mut res = Response::new(401, "Unauthorized", b"401 - Unauthorized".to_vec());
|
||||
res.headers_mut().push(("Set-Cookie".into(), AUTH_CLEAR.into()));
|
||||
Ok(res)
|
||||
};
|
||||
let cookie_list = match str::from_utf8(cl) {
|
||||
Ok(cl) => cl,
|
||||
Err(_) => return unauth(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user