mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
add BasicAuth support
This commit is contained in:
@@ -79,6 +79,18 @@ object JavalinSetup {
|
|||||||
ctx.result(e.message ?: "Internal Server Error")
|
ctx.result(e.message ?: "Internal Server Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.before { ctx ->
|
||||||
|
fun credentialsValid(): Boolean {
|
||||||
|
val (username, password) = ctx.basicAuthCredentials()
|
||||||
|
return username == serverConfig.basicAuthUsername && password == serverConfig.basicAuthPassword
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serverConfig.basicAuthEnabled && !(ctx.basicAuthCredentialsExist() && credentialsValid())) {
|
||||||
|
ctx.header("WWW-Authenticate", "Basic")
|
||||||
|
ctx.status(401).json("Unauthorized")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.routes {
|
app.routes {
|
||||||
path("api/v1/") {
|
path("api/v1/") {
|
||||||
GlobalAPI.defineEndpoints()
|
GlobalAPI.defineEndpoints()
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ class ServerConfig(config: Config, moduleName: String = MODULE_NAME) : SystemPro
|
|||||||
val webUIInterface: String by overridableConfig
|
val webUIInterface: String by overridableConfig
|
||||||
val electronPath: String by overridableConfig
|
val electronPath: String by overridableConfig
|
||||||
|
|
||||||
|
// Authentication
|
||||||
|
val basicAuthEnabled: Boolean by overridableConfig
|
||||||
|
val basicAuthUsername: String by overridableConfig
|
||||||
|
val basicAuthPassword: String by overridableConfig
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun register(config: Config) = ServerConfig(config.getConfig(MODULE_NAME))
|
fun register(config: Config) = ServerConfig(config.getConfig(MODULE_NAME))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,3 +16,8 @@ server.webUIEnabled = true
|
|||||||
server.initialOpenInBrowserEnabled = true
|
server.initialOpenInBrowserEnabled = true
|
||||||
server.webUIInterface = "browser" # "browser" or "electron"
|
server.webUIInterface = "browser" # "browser" or "electron"
|
||||||
server.electronPath = ""
|
server.electronPath = ""
|
||||||
|
|
||||||
|
# Authentication
|
||||||
|
server.basicAuthEnabled = false
|
||||||
|
server.basicAuthUsername = ""
|
||||||
|
server.basicAuthPassword = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user