diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt index d4602c26e..8f3ea0ef0 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt @@ -56,14 +56,16 @@ object JavalinSetup { config.enableCorsForAllOrigins() config.accessManager { handler, ctx, _ -> - fun credentialsValid(): Boolean { + fun basicAuthCredentialsValid(): 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") + if (serverConfig.authType != "none") { + if (serverConfig.authType == "basicAuth" && !(ctx.basicAuthCredentialsExist() && basicAuthCredentialsValid())) { + ctx.header("WWW-Authenticate", "Basic") + ctx.status(401).json("Unauthorized") + } } else { handler.handle(ctx) } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt index 0e977c025..db7406381 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt @@ -11,6 +11,7 @@ import com.typesafe.config.Config import xyz.nulldev.ts.config.GlobalConfigManager import xyz.nulldev.ts.config.SystemPropertyOverridableConfigModule import xyz.nulldev.ts.config.debugLogsEnabled +import kotlin.reflect.KProperty private const val MODULE_NAME = "server" class ServerConfig(config: Config, moduleName: String = MODULE_NAME) : SystemPropertyOverridableConfigModule(config, moduleName) { @@ -34,6 +35,15 @@ class ServerConfig(config: Config, moduleName: String = MODULE_NAME) : SystemPro val electronPath: String by overridableConfig // Authentication + val authType: String by object { + operator fun getValue(thisRef: R, property: KProperty<*>): String { + val propValue: String = overridableConfig.getValue(thisRef, property) + if (basicAuthEnabled) { + return "basicAuth" + } + return propValue + } + } val basicAuthEnabled: Boolean by overridableConfig val basicAuthUsername: String by overridableConfig val basicAuthPassword: String by overridableConfig diff --git a/server/src/main/resources/server-reference.conf b/server/src/main/resources/server-reference.conf index 04afefabc..b82e7af1f 100644 --- a/server/src/main/resources/server-reference.conf +++ b/server/src/main/resources/server-reference.conf @@ -14,7 +14,8 @@ server.webUIInterface = "browser" # "browser" or "electron" server.electronPath = "" # Authentication -server.basicAuthEnabled = false +server.authType = "none" # "none" or "basicAuth" or "token" +server.basicAuthEnabled = false # This is deprecated, use server.authType server.basicAuthUsername = "" server.basicAuthPassword = ""