Ktor 1.1.0 can't install features anymore
See original GitHub issueKtor Version
1.1.0 Kotlin Version 1.3.11
JVM Version, Operating System and Relevant Context
IntelliJ IDEA 2018.3.2 (Ultimate Edition) Build #IU-183.4886.37, built on December 17, 2018 JRE: 1.8.0_152-release-1343-b26 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.13.6
Code
import com.auth0.jwk.JwkProviderBuilder
import com.auth0.jwt.JWT
import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.algorithms.Algorithm
import com.fasterxml.jackson.core.util.DefaultIndenter
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import io.ktor.application.Application
import io.ktor.application.call
import io.ktor.application.install
import io.ktor.auth.Authentication
import io.ktor.auth.authenticate
import io.ktor.auth.authentication
import io.ktor.auth.jwt.JWTPrincipal
import io.ktor.auth.jwt.jwt
import io.ktor.features.CallLogging
import io.ktor.features.ContentNegotiation
import io.ktor.features.DefaultHeaders
import io.ktor.jackson.jackson
import io.ktor.response.respondText
import io.ktor.routing.Routing
import io.ktor.routing.get
import io.ktor.routing.post
import io.ktor.routing.route
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
object EdgeApplication {
@JvmStatic fun main(args: Array<String>) {
embeddedServer(Netty, port = 8080,
module = Application::jwtApplication
).start(wait = true)
}
}
fun Application.jwtApplication() {
val issuer = environment.config.property("jwt.domain").getString()
val audience = environment.config.property("jwt.audience").getString()
val realm = environment.config.property("jwt.realm").getString()
install(Authentication) {
val jwtVerifier = makeJwtVerifier(issuer, audience)
jwt {
verifier(jwtVerifier)
this.realm = realm
validate { credential ->
if (credential.payload.audience.contains(audience))
JWTPrincipal(credential.payload)
else
null
}
}
}
install(DefaultHeaders)
install(CallLogging)
install(ContentNegotiation) {
jackson {
configure(SerializationFeature.INDENT_OUTPUT, false)
registerModule(JavaTimeModule())
}
}
install(Routing) {
post("/auth") {
}
authenticate {
route("/who") {
handle {
val principal = call.authentication.principal<JWTPrincipal>()
val subjectString = principal!!.payload.subject.removePrefix("auth0|")
call.respondText("Success, $subjectString")
}
}
}
}
}
private val algorithm = Algorithm.HMAC256("secret")
private fun makeJwtVerifier(issuer: String, audience: String): JWTVerifier = JWT
.require(algorithm)
.withAudience(audience)
.withIssuer(issuer)
.build()
Description
Ever since upgrading to 1.1.0, I can no longer resolve the install function in my IDE. I can downgrade back to 1.0.1, and everything is fine, but as soon as I upgrade again to 1.1.0, install
can no longer be found, which makes most of the other parts of the code unresolve as well. I’ve tried refreshing all the gradle dependencies, which doesn’t seem to fix it either. When compiling with gradle in the command line, the same errors surface as well.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Top Results From Across the Web
WhatsNew 2.0
Kotlin Server and Client Framework for microservices, HTTP APIs, and RESTful services.
Read more >WhatsNew 1.6 | Ktor Framework
MissingApplicationFeatureException: Application feature Authentication is not installed.
Read more >WhatsNew 1.5 | Ktor Framework
Kotlin Server and Client Framework for microservices, HTTP APIs, and RESTful services.
Read more >WhatsNew 1.4
Kotlin Server and Client Framework for microservices, HTTP APIs, and RESTful services.
Read more >Migrating from 1.6.x to 2.0.x
To add all plugins at once, you can use the io.ktor:ktor-server ... In general, this API doesn't require an understanding of internal Ktor...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This should be fixed in 1.1.1
For me 1.1.1 solved this.