mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
Allow proxy authentication (#141)
This commit is contained in:
parent
135fa9fde6
commit
d67a24809b
@ -22,6 +22,7 @@ class Config
|
|||||||
property page_margin : Int32 = 30
|
property page_margin : Int32 = 30
|
||||||
property disable_login = false
|
property disable_login = false
|
||||||
property default_username = ""
|
property default_username = ""
|
||||||
|
property auth_proxy_header_name = ""
|
||||||
property mangadex = Hash(String, String | Int32).new
|
property mangadex = Hash(String, String | Int32).new
|
||||||
|
|
||||||
@[YAML::Field(ignore: true)]
|
@[YAML::Field(ignore: true)]
|
||||||
|
@ -93,8 +93,18 @@ class AuthHandler < Kemal::Handler
|
|||||||
call_next env
|
call_next env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_auth_proxy(env)
|
||||||
|
username = env.request.headers[Config.current.auth_proxy_header_name]?
|
||||||
|
unless username && Storage.default.username_exists username
|
||||||
|
return redirect env, "/login"
|
||||||
|
end
|
||||||
|
call_next env
|
||||||
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
if request_path_startswith env, ["/opds"]
|
if !Config.current.auth_proxy_header_name.empty?
|
||||||
|
handle_auth_proxy env
|
||||||
|
elsif request_path_startswith env, ["/opds"]
|
||||||
handle_opds_auth env
|
handle_opds_auth env
|
||||||
else
|
else
|
||||||
handle_auth env
|
handle_auth env
|
||||||
|
@ -3,13 +3,12 @@
|
|||||||
# This macro defines `is_admin` when used
|
# This macro defines `is_admin` when used
|
||||||
macro check_admin_access
|
macro check_admin_access
|
||||||
is_admin = false
|
is_admin = false
|
||||||
# The token (if exists) takes precedence over the default user option.
|
if !Config.current.auth_proxy_header_name.empty? ||
|
||||||
# this is why we check the default username first before checking the
|
Config.current.disable_login
|
||||||
# token.
|
is_admin = Storage.default.username_is_admin get_username env
|
||||||
if Config.current.disable_login
|
|
||||||
is_admin = Storage.default.
|
|
||||||
username_is_admin Config.current.default_username
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The token (if exists) takes precedence over other authentication methods.
|
||||||
if token = env.session.string? "token"
|
if token = env.session.string? "token"
|
||||||
is_admin = Storage.default.verify_admin token
|
is_admin = Storage.default.verify_admin token
|
||||||
end
|
end
|
||||||
@ -49,6 +48,8 @@ macro get_username(env)
|
|||||||
rescue e
|
rescue e
|
||||||
if Config.current.disable_login
|
if Config.current.disable_login
|
||||||
Config.current.default_username
|
Config.current.default_username
|
||||||
|
elsif (header = Config.current.auth_proxy_header_name) && !header.empty?
|
||||||
|
env.request.headers[header]
|
||||||
else
|
else
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user