mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
token auth
This commit is contained in:
@@ -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())) {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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 <R> 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
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user