mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-01 09:54:34 -05:00
Compare commits
1 Commits
master
...
token-auth
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53c3ac5676 |
@@ -56,14 +56,16 @@ object JavalinSetup {
|
|||||||
config.enableCorsForAllOrigins()
|
config.enableCorsForAllOrigins()
|
||||||
|
|
||||||
config.accessManager { handler, ctx, _ ->
|
config.accessManager { handler, ctx, _ ->
|
||||||
fun credentialsValid(): Boolean {
|
fun basicAuthCredentialsValid(): Boolean {
|
||||||
val (username, password) = ctx.basicAuthCredentials()
|
val (username, password) = ctx.basicAuthCredentials()
|
||||||
return username == serverConfig.basicAuthUsername && password == serverConfig.basicAuthPassword
|
return username == serverConfig.basicAuthUsername && password == serverConfig.basicAuthPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverConfig.basicAuthEnabled && !(ctx.basicAuthCredentialsExist() && credentialsValid())) {
|
if (serverConfig.authType != "none") {
|
||||||
ctx.header("WWW-Authenticate", "Basic")
|
if (serverConfig.authType == "basicAuth" && !(ctx.basicAuthCredentialsExist() && basicAuthCredentialsValid())) {
|
||||||
ctx.status(401).json("Unauthorized")
|
ctx.header("WWW-Authenticate", "Basic")
|
||||||
|
ctx.status(401).json("Unauthorized")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
handler.handle(ctx)
|
handler.handle(ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.typesafe.config.Config
|
|||||||
import xyz.nulldev.ts.config.GlobalConfigManager
|
import xyz.nulldev.ts.config.GlobalConfigManager
|
||||||
import xyz.nulldev.ts.config.SystemPropertyOverridableConfigModule
|
import xyz.nulldev.ts.config.SystemPropertyOverridableConfigModule
|
||||||
import xyz.nulldev.ts.config.debugLogsEnabled
|
import xyz.nulldev.ts.config.debugLogsEnabled
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
private const val MODULE_NAME = "server"
|
private const val MODULE_NAME = "server"
|
||||||
class ServerConfig(config: Config, moduleName: String = MODULE_NAME) : SystemPropertyOverridableConfigModule(config, moduleName) {
|
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
|
val electronPath: String by overridableConfig
|
||||||
|
|
||||||
// Authentication
|
// 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 basicAuthEnabled: Boolean by overridableConfig
|
||||||
val basicAuthUsername: String by overridableConfig
|
val basicAuthUsername: String by overridableConfig
|
||||||
val basicAuthPassword: String by overridableConfig
|
val basicAuthPassword: String by overridableConfig
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ server.webUIInterface = "browser" # "browser" or "electron"
|
|||||||
server.electronPath = ""
|
server.electronPath = ""
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
server.basicAuthEnabled = false
|
server.authType = "none" # "none" or "basicAuth" or "token"
|
||||||
|
server.basicAuthEnabled = false # This is deprecated, use server.authType
|
||||||
server.basicAuthUsername = ""
|
server.basicAuthUsername = ""
|
||||||
server.basicAuthPassword = ""
|
server.basicAuthPassword = ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user