Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BasicAuth is not resolved as a valid import in 1.2.0 #1133

Closed
nilsmagnus opened this issue May 15, 2019 · 22 comments
Closed

BasicAuth is not resolved as a valid import in 1.2.0 #1133

nilsmagnus opened this issue May 15, 2019 · 22 comments
Assignees

Comments

@nilsmagnus
Copy link

nilsmagnus commented May 15, 2019

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>
@lenalebt
Copy link

Can confirm, although I used Gradle. Started with a generated projet through the IntelliJ plugin, and only have seen afterwards that it did not support 1.2.0, did the upgrade manually. Workd with 1.1.4, does not with 1.2.0.

@e5l e5l self-assigned this May 16, 2019
@zeldigas
Copy link

zeldigas commented May 24, 2019

According to updated docs there is a new way for basic auth on client:

val client = HttpClient() {
    install(Auth) {
        basic {
            username = "username"
            password = "password"
        }
    }
}

But at least for maven based build it does not resolve io.ktor.client.features.auth.Auth either.

[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.31:compile (compile) on project my-project: Compilation failure: Compilation failure: 
[ERROR] ....App.kt:[11,37] Unresolved reference: Auth

@zeldigas
Copy link

Looks like there is nothing, but metadata files in jar archive and documentation for maven projects is misleading. To make it work, dependency name should be adjusted with suffix -jvm

<dependency>
    <groupId>io.ktor</groupId>
    <artifactId>ktor-client-auth-jvm</artifactId>
    <version>${ktor.version}</version>
</dependency>

Or basic auth

<dependency>
   <groupId>io.ktor</groupId>
   <artifactId>ktor-client-auth-basic-jvm</artifactId>
   <version>${ktor.version}</version>
</dependency>

@SimonSchubert
Copy link

I accidentally created a duplicate issue yesterday evening. #1150

@zeldigas When I add ktor-client-auth-jvm to my android project dependency it successfully builds but doesn't send any Authorization header.

@e5l
Copy link
Member

e5l commented 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.

@nilsmagnus
Copy link
Author

Thanks @e5l , the solution proposed by @zeldigas solves the issue.

@e5l
Copy link
Member

e5l commented May 24, 2019

Awesome :)

@Grannath
Copy link

Grannath commented Jun 3, 2019

@nilsmagnus This issue should not be closed. Documentation and project generator are both producing the old, wrong version.

@e5l e5l reopened this Jun 3, 2019
@e5l
Copy link
Member

e5l commented Jun 3, 2019

Thanks for the notice. We'll update the docs and generator.

@smaudet
Copy link

smaudet commented Jul 8, 2019

This is still broken.

@smaudet
Copy link

smaudet commented Jul 8, 2019

gradle/kotlin-dsl-samples#1117

I know this is unrelated but, cmon guys, its been almost two years and KT and friends just feel like so much hot garbage in practice, unstable, can't build, project generators have showstopping bugs in them, IntelliJ seems to like to crash, on top of that the whole Gradle ecosystem is a mess to debug??

You've had this bug for 2 months, it can't have been that hard to fix (for anyone who knows this system they've constructed). What happened, did all the funding dry up or something? Or is this just incredibly unstable that two patch versions broke this again?

@e5l
Copy link
Member

e5l commented Jul 30, 2019

Hi @smaudet, I can't reproduce the problem. What do you mean by still broken?

@nilsmagnus
Copy link
Author

@e5l , it means that the example in the docs (https://ktor.io/clients/http-client/features/auth.html) is not working. The dependency stated there is not resolved.

@e5l
Copy link
Member

e5l commented Aug 1, 2019

Could you try?

implementation "io.ktor:ktor-client-auth-jvm:$ktor_version"

@nilsmagnus
Copy link
Author

Yes, I could try that. But the documentation states

implementation "io.ktor:ktor-client-auth:$ktor_version"

@Gloix
Copy link

Gloix commented Aug 9, 2019

For me neither ktor-client-auth nor ktor-client-auth-jvm work for me. I don't know how people are authenticating requests with ktor.

@banshee
Copy link

banshee commented 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.

@e5l
Copy link
Member

e5l commented Nov 27, 2019

@nilsmagnus, the documentation was fixed here: https://ktor.io/clients/http-client/features/auth.html
@banshee could you file a separate issue for the plugin?

@e5l
Copy link
Member

e5l commented May 26, 2020

The docs are fixed here: https://ktor.io/clients/http-client/features/auth.html. The plugin is fixed in 1.3.2 release.

Guys, great thanks for the investigation!

@e5l e5l closed this as completed May 26, 2020
@orchestr7
Copy link

orchestr7 commented Oct 8, 2020

Guys, with such a bad documentation - no one will be using ktor.
Now it is awful. See how great is documentation in Spring.

Please include at least dependencies and corresponding imports in code snippets with examples.

@hhariri
Copy link
Contributor

hhariri commented Oct 8, 2020

We're working on it. Thanks.

@NurseyitTursunkulov
Copy link

NurseyitTursunkulov commented Dec 1, 2020

awful documentation awful!!!! work on it please!

@ktorio ktorio locked and limited conversation to collaborators Dec 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests