https://kotlinlang.org logo
#ktor
Title
# ktor
j

jean

02/24/2022, 3:13 PM
I’m declaring my server with the following :
Copy code
fun main() {
    embeddedServer(
        factory = CIO,
        environment = applicationEngineEnvironment {
            config = HoconApplicationConfig(ConfigFactory.load())
            connector {
                port = 8080
            }
            module(Application::module)
        },
    ).start(wait = true)
}

fun Application.module() {
    val jwtValues = jwtValues(environment)
    val pbkdf2Values = pbkdf2Values(environment)
    val database = SamkjoringDatabase()

    configureRouting(jwtValues, pbkdf2Values, database)
    configureSerialization()
    configureSecurity()
    configureTemplate()
}
and my
resources/application.conf
Copy code
jwt {
    secret = "7lgeBk06UhkLRLFDhQn3"
    issuer = "<http://0.0.0.0:8080/>"
    audience = "<http://0.0.0.0:8080/login>"
    realm = "Access to 'login'"
}
pbkdf2 {
    salt = "qdQk4P2TNvHc"
    iterations = "10000"
    keyLength = "512"
}
But I get the error
Exception in thread “main” io.ktor.config.ApplicationConfigurationException: Property jwt.secret not found.
at io.ktor.config.HoconApplicationConfig.property(HoconApplicationConfig.kt:15)
at no.samkjoring.plugins.auth.JwtKt.jwtValues(jwt.kt:27)
What am I missing here?
a

Amaan

02/24/2022, 8:22 PM
What version of Ktor are you using? Also, could you share your
jwtValues
function? I imagine you should have a line like
Copy code
environment.config.property("jwt.secret").getString()
assuming
jwt
is a root property in the HOCON file
j

jean

02/25/2022, 8:42 AM
Copy code
private const val JWT_SECRET = "jwt.secret"
private const val JWT_ISSUER = "jwt.issuer"
private const val JWT_AUDIENCE = "jwt.audience"
private const val JWT_REALM = "jwt.realm"

fun jwtValues(environment: ApplicationEnvironment) = JwtValues(
    secret = environment.config.property(JWT_SECRET).getString(),
    issuer = environment.config.property(JWT_ISSUER).getString(),
    audience = environment.config.property(JWT_AUDIENCE).getString(),
    realm = environment.config.property(JWT_REALM).getString()
)
I’m using ktor 1.6.7
I just figured it out, I was not putting the application.conf file in the correct folder. My previous ktor project had a resource folder directly under the root. The new one I just created with the online ktor project generator has src/main/resources
🙌 1
79 Views