Add cookie sharing with subdomains

This commit is contained in:
Omar Roth 2018-11-15 16:41:43 -06:00
parent 6db235becf
commit bf867c3fcf
2 changed files with 15 additions and 4 deletions

View file

@ -846,8 +846,13 @@ post "/login" do |env|
secure = false
end
env.response.cookies["SID"] = HTTP::Cookie.new(name: "SID", value: sid, expires: Time.now + 2.years,
secure: secure, http_only: true)
if CONFIG.domain
env.response.cookies["SID"] = HTTP::Cookie.new(name: "SID", domain: ".#{CONFIG.domain}", value: sid, expires: Time.now + 2.years,
secure: secure, http_only: true)
else
env.response.cookies["SID"] = HTTP::Cookie.new(name: "SID", value: sid, expires: Time.now + 2.years,
secure: secure, http_only: true)
end
else
error_message = "Invalid username or password"
next templated "error"
@ -891,8 +896,13 @@ post "/login" do |env|
secure = false
end
env.response.cookies["SID"] = HTTP::Cookie.new(name: "SID", value: sid, expires: Time.now + 2.years,
secure: secure, http_only: true)
if CONFIG.domain
env.response.cookies["SID"] = HTTP::Cookie.new(name: "SID", domain: ".#{CONFIG.domain}", value: sid, expires: Time.now + 2.years,
secure: secure, http_only: true)
else
env.response.cookies["SID"] = HTTP::Cookie.new(name: "SID", value: sid, expires: Time.now + 2.years,
secure: secure, http_only: true)
end
end
env.redirect referer

View file

@ -16,6 +16,7 @@ class Config
hmac_key: String?,
full_refresh: Bool,
geo_bypass: Bool,
domain: String?,
})
end