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.

BasicAuth is not resolved as a valid import in 1.2.0

See original GitHub issue

Ktor Version

1.2.0

Ktor Engine Used(client or server and name)

Ktor-engine: Netty, httpclient: Apache

JVM Version, Operating System and Relevant Context

java: 11.0.2-open OS: linux, ubuntu build-system: maven

Feedback

After upgrade to version 1.2.0 from verison 1.1.4, the BasicAuth class fails to resolve: ‘import io.ktor.client.features.auth.basic.BasicAuth’ does not work.

Error:

[ERROR] /home/larsgard/workspace/ktor-test/src/main/kotlin/Main.kt: (8, 43) Unresolved reference: BasicAuth
[ERROR] /home/larsgard/workspace/ktor-test/src/main/kotlin/Main.kt: (16, 21) Unresolved reference: BasicAuth
[ERROR] /home/larsgard/workspace/ktor-test/src/main/kotlin/Main.kt: (17, 17) Unresolved reference: username
[ERROR] /home/larsgard/workspace/ktor-test/src/main/kotlin/Main.kt: (18, 17) Unresolved reference: password
[INFO] Kotlin compile iteration: /home/larsgard/workspace/ktor-test/src/main/kotlin/Main.kt

Sample application with Main.kt and pom.xml below:

src/main/kotlin/Main.kt:

import io.ktor.application.call
import io.ktor.client.HttpClient
import io.ktor.client.engine.apache.Apache
import io.ktor.http.ContentType
import io.ktor.response.respondText
import io.ktor.routing.get
import io.ktor.routing.routing
import io.ktor.client.features.auth.basic.BasicAuth
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty


fun main(args: Array<String>) {
    val server = embeddedServer(Netty, port = 8080) {
        val myClient = HttpClient(Apache) {
            install(BasicAuth) {
                username = "username"
                password = "password"
            }
        }
        routing {
            get("/") {
                call.respondText("Hello World!", ContentType.Text.Plain)
            }
            get("/demo") {
                call.respondText("HELLO WORLD!")
            }
        }
    }
    server.start(wait = true)

}

Maven file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>no.nils.ktortest</groupId>
  <artifactId>ktortest</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>ktortest</name>

  <properties>
    <source.java.version>11</source.java.version>
    <target.java.version>11</target.java.version>
    <kotlin.version>1.3.31</kotlin.version>
    <ktor.version>1.2.0</ktor.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <kotlin.compiler.incremental>true</kotlin.compiler.incremental>
  </properties>


  <dependencies>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib</artifactId>
      <version>${kotlin.version}</version>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib</artifactId>
      <version>${kotlin.version}</version>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-server-netty</artifactId>
      <version>${ktor.version}</version>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-client-apache</artifactId>
      <version>${ktor.version}</version>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-server-core</artifactId>
      <version>${ktor.version}</version>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-client-auth-basic</artifactId>
      <version>${ktor.version}</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>${source.java.version}</source>
          <target>${target.java.version}</target>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>kotlin-maven-plugin</artifactId>
        <groupId>org.jetbrains.kotlin</groupId>
        <version>${kotlin.version}</version>
        <executions>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <args>-Xuse-experimental=kotlin.Experimental</args>
            </configuration>
          </execution>
          <execution>
            <id>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
            <configuration>
              <args>-Xuse-experimental=kotlin.Experimental</args>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
</project>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:22 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
e5lcommented, May 24, 2019

Hi @nilsmagnus. Thanks for the report. As mentioned above, the feature Auth with basic provider is a common preferred way instead of BasicAuth.

There is no metadata for JVM artifacts for now, and the artifact ktor-client-auth-jvm should be used.

3reactions
bansheecommented, Nov 26, 2019

Has ktor been abandoned? To a brand-new user, seems like some very basic stuff is wrong. I just tried to use the intellij plugin and the code it produces doesn’t even compile due to this problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

express-basic-auth | Yarn - Package Manager
If a request is found to not be authorized, it will respond with HTTP 401 and a configurable body (default empty).
Read more >
Basic Auth example code does not work - Dash Python
I've just tested the guide tutorial and everything seems to work fine. Can you post your code so we can check if something...
Read more >
Reference - Authentication REST API 1.2.0 - support@intershop
Every REST endpoint supports authentication using basic authentication. ... getKeyID()), "Could not resolve key with id " + header.
Read more >
Incorrect connection request credentials (v1.2)
We have a case where Genie is provisioning new cpe's, but we want to import the old ones that are managed by openACS....
Read more >
Solved: Alfresco 6.2 - Showing the basic auth dialog when
I need it because we inject the basicAuth with an external application to download documents. Actually, we can not because the dialog doesn't ......
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