question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ktor 1.1.0 can't install features anymore

See original GitHub issue

Ktor 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.

screen shot 2018-12-25 at 2 16 05 am screen shot 2018-12-24 at 5 14 36 pm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
cy6erGn0mcommented, Dec 26, 2018

This should be fixed in 1.1.1

1reaction
wemcommented, Dec 27, 2018

For me 1.1.1 solved this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found